Home > Net >  Please take a look at the teacher, the MVC using ajax, why "new {id=obj. Id}" this place w
Please take a look at the teacher, the MVC using ajax, why "new {id=obj. Id}" this place w

Time:10-08

Var strHtml='& lt; Tbody> Id Name UnitPrice ';
$. Ajax ({
Url: "/Book/ShowList",
Data: {id: id, name: the name},
DataType: "json",

Success: the function (result) {
$. Each (result, function (independence idx, obj) {
StrHtml +='& lt; tr> '
StrHtml +=obj. Id + '& lt;/td> '
StrHtml +=obj. Name + '& lt;/td> '
StrHtml +=obj. UnitPrice + '& lt;/td> '
StrHtml +='& lt; td> @ Html. ActionLink (" Details ", "Details", new {id=obj. Id}, new {@ class=""}) & lt;/td> '
StrHtml +='& lt;/tr> '
StrHtml +='& lt;/tbody> '
})
$(' # table1). The empty (), append (strHtml);

}
})


The obj. Id can display properly, the following obj. To a constant can also display the Id, just can't use variables,

CodePudding user response:

Because the code doesn't meet js variables,
Can only use the background variables in js,

CodePudding user response:

{id: id, name: the name}
Side of the id, name attribute should be what the background variables, such as after you get the object, should object. Id, rather than the object. Id

CodePudding user response:

 
Var strHtml='& lt; Tbody> Id Name UnitPrice ';
$. Ajax ({
Url: "/Book/ShowList",
Data: {id: id, name: the name},
DataType: "json",

Success: the function (result) {
$. Each (result, function (independence idx, obj) {
StrHtml +='& lt; tr> '
StrHtml +=obj. Id + '& lt;/td> '
StrHtml +=obj. Name + '& lt;/td> '
StrHtml +=obj. UnitPrice + '& lt;/td> '
StrHtml +='& lt; td> @ Html. ActionLink (" Details ", "Details", new {id='+ obj. Id +}, new {@ class=""}) & lt;/td> '
StrHtml +='& lt;/tr> '
StrHtml +='& lt;/tbody> '
})
$(' # table1). The empty (), append (strHtml);

}
})

CodePudding user response:

Emmmmm is an a label why so complicated

CodePudding user response:

{id: id, name: the name}
Side of the id, name attribute should be compatible with the background variables, such as after you get the object, should object. Id, rather than the object. The id

All not line, with constant can,
Detail page link can't be a constant

CodePudding user response:

Because in the HTML obj. Id as a string, rather than js variables, so should be changed to "new {Id='+ obj. Id +}"

CodePudding user response:

Because in the HTML obj. Id as a string, rather than js variables, so should be changed to "new {Id='+ obj. Id +}"

This also tried and tried again, still won't do,
Originally the variables from the string points out, to connect again, should be able to, but it was not, then red line,

CodePudding user response:

Using JSON. Stringify ({id: id, name: the name}) try

CodePudding user response:

You can put ViewTag directly server serialization,
Or you can use the method of upstairs also,
  • Related