【问题标题】:Using Ajax.BeginForm in MVC4在 MVC4 中使用 Ajax.BeginForm
【发布时间】:2013-09-17 12:01:24
【问题描述】:

我有类似的东西

@using (Ajax.BeginForm("Next", "Controll", null, new AjaxOptions() { UpdateTargetId = "updateRegion", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }))
{
 <div id="updateRegion">
 @Html.Partial("_callingFromPartial", Model.List[0])
</div>
}


       @Html.RadioButtonFor(item => Model.OptionSelected, Model.IdOption, new { id = "select" + Model.IdOption })
       <label>@Model.OptionText</label>
       <input type="submit" value="Next"/>


[HttpGet]
    public ActionResult Next(Bu.Models.ChoiceQuestion itemReturn)
    {
        CurrentItem = Itens[refe+1];
        return PartialView("_callingFromPartial", CurrentItem);
    }

但它并没有像我想要的那样工作,我正在尝试在#updateRegion 中加载下一个内容,但它显示“找不到资源”。 ,这有什么问题吗?

【问题讨论】:

  • 问题是表单中的“method='post'”默认值,现在我用 'Ajax.BeginForm("Next", "Controll", null, new AjaxOptions() { UpdateTargetId = "updateRegion", InsertionMode = InsertionMode.Replace, HttpMethod = "GET", new {method = "get"} }' 它正在工作,但是,它仍然在干净的文档页面中显示结果.

标签: asp.net-mvc


【解决方案1】:

是的。 首先,您在需要替换的 div 中 即更新区域 根据您的代码,它将替换所有内容

new AjaxOptions() { UpdateTargetId = "updateRegion", InsertionMode = InsertionMode.Replace

您需要在需要替换的元素内和周围声明 div。

在这种情况下建议使用部分视图。

【讨论】:

    【解决方案2】:

    尝试将 div "updateRegion" 放在表单标签内。 喜欢:-

    @using (Ajax.BeginForm("Next", "Controll", null, new AjaxOptions() { UpdateTargetId = "updateRegion", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }))
    { 
      <div id="updateRegion">
      </div>
      @Html.RadioButtonFor(item => Model.OptionSelected, Model.IdOption, new { id = "select" + Model.IdOption })
      <label>@Model.OptionText</label>
      <input type="submit" value="Next" />
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多