Reputation: 4570
I'm going to implement some search functionality. But I'm still failing to pass searchString
to the controller.
@model IEnumerable<ASF.NWS.Entities.DX.News>
@using (Ajax.BeginForm("Index", "News", new { searchString = searchString }, new AjaxOptions { UpdateTargetId = "showNews", InsertionMode = InsertionMode.Replace, OnFailure = "error" }))
{
<input type="text" id="searchString" />
<input type="submit" value="submit" />
}
My controller:
public ActionResult Index(string searchString) // <-- searchString comes null
{
}
Upvotes: 0
Views: 31
Reputation:
You need to give you input a name attribute
<input type="text" name="searchString" id="searchString" />
Its the name
and value
attributes of each control that are sent when a form is submitted (the id
attribute is probably not required unless you are using javascript to access the element)
You also need to remove new { searchString = searchString }
from the Ajax.BeginForm
helper. Your trying to set a route value, but searchString
will be undefined
Upvotes: 4