Asp.Net Axaj.BeginForm和放大器; UpdateTargetId不工作放大器、工作、Net、Asp

由网友(未未未成年°)分享简介:我有这样的的HomeController public ActionResult Details(string id){var customer = Customers.GetCustomersById(id);return PartialView("CustomerDetails", customer);}这在的...

我有这样的的HomeController

public ActionResult Details(string id)
    {
        var customer = Customers.GetCustomersById(id);
        return PartialView("CustomerDetails", customer);
    }

这在的Index.aspx

<div>
        <% using (Ajax.BeginForm("Details", new AjaxOptions
           {
               UpdateTargetId = "customerDetails",
               InsertionMode = InsertionMode.Replace,
               HttpMethod = "POST"
           }))
           { %>
        <p>
            Customer:
            <%=Html.DropDownList("id")%></p>
        <p>
            <input type="submit" value="Details" /></p>
        <% } %>
    </div>
    <div id="customerDetails">
</div>

最后,在 CustomerDetails.ascx 我:

  <fieldset>
        <legend>Fields</legend>
        <p>
            Name:
            <%= Html.Encode(Model.Name) %>
        </p>
        <p>
            Credit:
            <%= Html.Encode(Model.Credit) %>
        </p>
        <p>
            CustomerID:
            <%= Html.Encode(Model.CustomerID) %>
        </p>
    </fieldset>
    <p>
        <%=Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) %> |
        <%=Html.ActionLink("Back to List", "Index") %>
    </p>

CustomerDetails.ascx生成通过右键单击详细信息,方法,并选择添加视图,然后选择局部视图和强类型的视图。

CustomerDetails.ascx was generated by right clicking on the Details-method and choosing "Add View", and selecting partial view and strongly typed view.

我会想这个更新一个名为CustomerDetails的里面的index.html DIV内的客户详细信息的Ajax的方式。的问题是,pressing详细按钮后,一个新的页面打开其中,与所述正确的细节。输出页面没有母版页的颜色或布局。

I'd want this to update the customer details in "Ajax-manner" inside a div called "customerDetails" inside Index.html. The problem is that after pressing Details-button, a new page is opened where with the correct details. The output page has no master page colors or layouts.

如果我调试的详细信息,方法,客户对象的内容是正确的。

If I debug at Details-method, the contents of customer object is correct.

任何帮助AP preciated!

Any help appreciated!

/ POM

推荐答案

最有可能的罪魁祸首是,你是不是包括在页面上MicrosoftAjax.js和MicrosoftMvcAjax.js。这使得JavaScript的失败,因为它无法找到所需的功能和形式通常通过提交,而不是阿贾克斯。

The most likely culprit is that you aren't including MicrosoftAjax.js and MicrosoftMvcAjax.js on the page. This causes the javascript to fail because it can't find the necessary functions and the form submits normally instead through Ajax.

阅读全文

相关推荐

最新文章