Ajax.BeginForm replace whole page

I have read many similar questions on the internet, but still cannot figure out the problem. Mine Ajax.BeginForm

returns a message across PartialView

in Controller

, but the string replaces the entire page.

View

:

   @using (Ajax.BeginForm("NoMoreItem", "ProductListing", 
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = string.Concat("NoMoreItemSection1-", counter)
}, new { @id = string.Concat("NoMoreItemForm1-", counter) }))
{
    <input type="hidden" value="@Model.Email" name="email" />
    <input type="hidden" value="@i.code" name="code" />
    <input type="submit" value="notify me" />
}
</div>

      

My controller:

public ActionResult NoMoreItem(string email, string productCode)
{
    string message;
    _waitinglist.Save(email, productCode);
    message = "Item added to Waiting List";
    return PartialView("ItemAdded", message);
}

      

ItemAdded

View:

@model string
<div>
    @Model
</div>

      

I referenced the jquery.unobtrusive-ajax.js

file in _Layout.cshtml

, so it doesn't seem to be the reason.

Does anyone have an idea why the post is replacing the entire page?

+3


source to share


2 answers


Make sure you link to MS files

 <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

      



Also I think you want to post and not receive.

+1


source


Double check that jquery.unobtrusive-ajax.js is loaded correctly on the page and validate your product code name in the input tag (must be equal to the action parameter).



Let me know if this solves your problem.

0


source







All Articles