views:

16

answers:

1

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" />
            </p>
                 <% Html.Hidden("id", ViewData["id"]);%>   
            <% Html.EndForm(); %>
+2  A: 

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)
Alastair Pitts