当我使用Ajax.ActionLink()发布表单时,我得到所有属性的空值。我也尝试过使用@ ajax.beginform()。但我最终得到了一个错误"意想不到的令牌u"在控制台中。请帮忙。
我的班级就像这样
public class Search
{
public string SearchText { get; set; }
public int ContinentId { get; set; }
public string City { get; set; }
}
我的观点就像这样
@model MvcApplication5.Models.BusinessLogic.Search
@{
ViewBag.Title = "Index";
var continetList = (SelectList)ViewBag.TargetContinentName;
var infoTypesList = (List<SelectListItem>)ViewBag.Infotype;
}
@Html.TextBoxFor(m => m.SearchText)<br/>
@Ajax.ActionLink("Search", "Search", "Home", new AjaxOptions{ HttpMethod = "POST", UpdateTargetId = "submitId", InsertionMode = InsertionMode.Replace,
LoadingElementId = "loadingId"})
</div>
我的控制器就像这样
//POST:/Home/
[HttpPost]
public PartialViewResult Search(Search search, int? page)
{
//Code goes here
//Here the object search is giving me null values for all the properties
return PartialView("_Search",listInfo);
}
答案 0 :(得分:0)
你必须像这样使用 Ajax.BeginForm :
@model MvcApplication5.Models.BusinessLogic.Search
@{
ViewBag.Title = "Index";
var continetList = (SelectList)ViewBag.TargetContinentName;
var infoTypesList = (List<SelectListItem>)ViewBag.Infotype;
}
@using (Ajax.BeginForm("Search", "Home",
new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "submitId",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "loadingId"
},
new { page = 1}))
{
@Html.TextBoxFor(m => m.SearchText)
@Html.HiddenFor(m=>m.ContinentId)
@Html.HiddenFor(m=>m.City)
<input type="submit" value="Search" name="Search"/>
}