views:

228

answers:

2

Thare is two forms in a page first one for searching and another for deleting....

<table><tr><td>
<% using(Html.BeginForm("ViewList","ControllerName",
[values],FormMethod.Post,new{id="viewListForm"}))
{ %>
    Name:    <%=Html.TextBox("Name", "[value]", new { maxlength = "250" })%>
    Location: <%=Html.TextBox("Location", "[Value]", new { maxlength = "250" })%>
    <input type="submit" id="Search" name="Search" value="Search" />

<% } %>
</td></tr>
<tr><td>
<% using(Html.BeginForm("DeleteList","ControllerName",
         new { name=?,location=? },[values],FormMethod.Post,
          new{id="deleteListForm"}))
{ %>
   [here the code for all items displayed in a table.]

  <input type="submit" id="Delete" name="Delete" value="Delete" />

When delete buttom pressed i need to pass two parameters ie name
and location. The values of name and location are in the above viewListForm.
How i take this value from the viewListForm at run time ?

<% } %>
</td></tr><table>
A: 

Use javascript to populate hidden inputs.

Or use javascript to dynamically change the action of the search form.

Or dynamically create a form in jQuery for example and submit it.

bingle
and if the user doesn't have javascript?
roryf
A: 

You will need to have a controller action that takes a FormCollection as parameter

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ActionName(FormCollection collection)
{
    // you can pull key value pair from the posted collection
    string formValue = collection["InputId"]
}
tarn
Additional values that are not on the form can be added as hidden parameters or as route values. Route values will need to route correctly to an action method with the route names are parameters.
tarn