What should I use to pass value in asp.net mvc posting form?
I am passing the edited value
and retrieving it back but I dont get back the id
value.. how do I get back the value for Id...The id value will actually remain the same..all I need to do is pass it back again...
public ActionResult EditValue(int id)
{
ViewData["id"]=id;
ViewData["Value"]=GetOriginalValue();
return View();
}
[HttpPost]
public ActionResult EditValue(string Value)
{
//How do I get the id value back..it will always be the same
UpdateValue(id,Value);
}
//---VIEW--
<% Html.BeginForm(); %>
<div class="editor-label">
<%= Html.Label("Value")%>
</div>
<div class="editor-field">
<%= Html.TextBox("Value",ViewData["Value"])%>
<%= Html.ValidationMessage("Value")%>
</div>
<p>
<input type="submit" value="Update" /&g开发者_如何学Ct;
</p>
<% Html.Hidden("id", ViewData["id"]);%>
<% Html.EndForm(); %>
if you put int id
into your parameters for the post, it should pick up the hidden form element... Or you can use the FormCollection class and access the individual form elements.
So your method signature would look like:
public ActionResult EditValue(int id, string Value)
or
public ActionResult EditValue(FormCollection form)
精彩评论