连续的AJAX帖子C#MVC

时间:2014-11-04 14:04:34

标签: c# asp.net-mvc asp.net-ajax

我正试图通过AJAX连续发布,但它没有第二次发布,我猜这是因为页面没有重新加载。帖子来自表格中的不同单元格,并转到不同的ActionResults,所有内容都位于MVC部分,我将渲染所有内容。

我在MVC工作,这是我发布帖子的视图。

第一篇文章:

<tr>
@using (Ajax.BeginForm("ChangeContactInformation", null, new AjaxOptions { UpdateTargetId = "profileTable" }, FormMethod.Post))
{
  <td>
      @Html.TextBoxFor(x => x.CurrentUser.ContactInformation, new { Name = "ContactInformation" })<button type="submit">Spara</button>
  </td>
}
</tr>

第二篇文章:

<tr>
@using (Ajax.BeginForm("ChangeTemporaryMessage", null, new AjaxOptions { UpdateTargetId = "profileTable" }, FormMethod.Post))
{
  <td>
      @Html.TextBoxFor(x => x.CurrentUser.ContactInformation, new { Name = "TemporaryMessage" })<button type="submit">Spara</button>
  </td>
}
</tr>

这是控制器:

        [HttpPost]
    public ActionResult ChangeTemporaryMessage(string TemporaryMessage)
    {
        var model = (ProfileBlockViewModel)Session["model"];
        ConnectionHelper.ChangeTemporaryMessage(TemporaryMessage, model.CurrentUser.UserID);
        return RedirectToAction("Index", model);
    }

    [HttpPost]
    public ActionResult ChangeContactInformation(string ContactInformation)
    {
        var model = (ProfileBlockViewModel)Session["model"];
        ConnectionHelper.ChangeContactInformation(ContactInformation, model.CurrentUser.UserID);
        return RedirectToAction("Index", model);
    }

所以第一个工作完美,但问题是,在该帖子完成并且数据更新后,我无法从第二个发布或从第一个发布 - 没有连续帖子允许,这正是我想要。
无论如何我能做到这一点吗?

提前致谢!
deSex

1 个答案:

答案 0 :(得分:1)

叹息......通过进行以下更改使其工作:

我在视图中更改了这个

    <tr>
        @using (Ajax.BeginForm("ChangeTemporaryMessage", null, new AjaxOptions { UpdateTargetId = "profileTable" }, FormMethod.Post))
        {
            <td>
                @Html.TextBoxFor(x => x.CurrentUser.ContactInformation, new { Name = "TemporaryMessage" })<button type="submit">Spara</button>
            </td>
        }
    </tr>

对此:

    <td>
    @using (Ajax.BeginForm("ChangeTemporaryMessage", null, new AjaxOptions { UpdateTargetId = "profileTable" }, FormMethod.Post))
    {
        @Html.TextBoxFor(x => x.CurrentUser.TemporaryMessage, new { Name = "TemporaryMessage" })<button type="submit">Spara</button>
    }
    </td>

我通过将@using指令放在&lt;中来解决它。 td&gt;标签,它之前就是它。

不确定为什么这是启用连续帖子,所以如果你知道随时教育我! :)

问候
deSex