【问题标题】:ASP.NET MVC posting with Ajax.BeginForm returns blank view使用 Ajax.BeginForm 发布的 ASP.NET MVC 返回空白视图
【发布时间】:2009-04-01 18:19:25
【问题描述】:

我有一个包含多个输入的页面 - 我正在使用 Ajax.BeginForm 为每组输入构建一个表单。

<% using (Ajax.BeginForm(new AjaxOptions() { InsertionMode = InsertionMode.InsertAfter, HttpMethod = "POST" }))
   { %>
     <input class="smallInput" type="text" name="duration"/>
     <input type="submit" value="Add" />
<% } %>

控制器长这样

   [AcceptVerbs("POST")]
   public ActionResult AddExercise(FormCollection form)
   {

       // some save logic...

       return Content(string.Empty);

   }

这行得通 - 数据被提交到我的控制器并被保存。

但是,每次发生这种情况时,我的页面都会被空白页面替换。如果我从我的操作中显式返回一个视图,则会出现该视图。但我希望它提交表单,让我现有的页面保持原样。

【问题讨论】:

    标签: ajax asp.net-mvc forms


    【解决方案1】:

    我的页面中没有包含 MVC Ajax javascript 文件。添加这些包含解决了问题。

    【讨论】:

    【解决方案2】:

    您需要指定要更新的 DOM 元素的 id:

    <% using (Ajax.BeginForm(new AjaxOptions() { 
        UpdateTargetId = "someID", 
        InsertionMode = InsertionMode.InsertAfter, 
        HttpMethod = "POST" }))
    { %>
        <input class="smallInput" type="text" name="duration"/>
        <input type="submit" value="Add" />
    <% } %>
    

    【讨论】:

      猜你喜欢
      • 2017-02-03
      • 2011-10-15
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多