如何修复 mvc 4 razor 中的 ajax 重定向?
<div id="ajax-container">
@using (Ajax.BeginForm("EditPlace", "Index", new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "ajax-container" }))
{
@Html.HiddenFor(m => m.Id);
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Address)
@Html.TextBoxFor(m => m.Phone)
@Html.TextBoxFor(m => m.Site)
@Html.TextAreaFor(m => m.WorkTime)
<input type="submit" value="ОК" />
}
服务器端:
public void EditPlace(int id, string name, string address, string phone, string site, string worktime)
{
var company = _entity.Companies.FirstOrDefault(linqCompany => linqCompany.Id == id);
if (company == null)
return;
company.Name = name;
company.Address = address;
company.Phone = phone;
company.Site = site;
company.WorkTime = worktime;
_entity.SaveChanges();
}
单击按钮后,我被重定向到 Index/EditPlace。