开发者

Asp.Net Axaj.BeginForm & UpdateTargetId not working

I have this in HomeController:

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

And this in 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>

And finally in CustomerDetails.ascx I have:

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

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

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.

Any help appreciated!

/pom


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜