Ajax.BeginForm重定向而不是替换div容器

时间:2012-08-21 19:39:58

标签: ajax asp.net-mvc razor

  

可能重复:
  Ajax.BeginForm results in redirect to partial view instead of in-place

如何在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上重定向。

0 个答案:

没有答案