質問

I have parsed the json string and displayed it in the form of table and against each record I placed a "Edit" button. My code is :

for (var i = 0 ; i < data.Homes.length ; i++) {
results += "<form><tr><td>" + data.Homes[i].ID + "</td><td>" + data.Homes[i].Name + "</td>";
 results += "<td><a href=\"#\" onclick=\"\">Edit</a></td>";
 results += "<input type=\"hidden\" value=\"" + data.Homes[i].ID + "\" />";
 results += "</tr></form>";
     }  

I want the "Edit" Button to link to another view , and I am passing the id in a hidden field. Through id I can query database and get the paritcular record against this id. But I don't know how to access the value of the hidden field in the view.

I need help in this. Thanks in advance

役に立ちましたか?

解決

Give the hidden field a name attribute, and then add an input variable to the action method you're submitting to:

View:

<input type='hidden' name='myIdField' />

Controller Action:

[Post]
public ActionResult SomePostMethod(int myIdField)
{
....
}

他のヒント

As your edit is link , it is not going to do the post to the controller . One of the simple way to get it through the querystring make your edit URL like this

                 Edit?Id=data.Homes[i].ID 

Now you can access the querystring anywhere either in client side or server side.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top