jkl
jkl

Reputation: 675

Ajax.BeginForm replace entire page

I have read many of similar questions on the web but still can't figure out the problem. My Ajax.BeginForm returns a message through 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 jquery.unobtrusive-ajax.js file in _Layout.cshtml so it seems not be the reason.

Does anyone have idea why the message replace the entire page?

Upvotes: 4

Views: 1283

Answers (3)

mytech
mytech

Reputation: 1

For those who went round and round on google and couldn't found solution,

make sure web.config has UnobtrusiveJavaScriptEnabled=true in appsettings .

Upvotes: 0

Carlos Araujo
Carlos Araujo

Reputation: 474

Double check if your jquery.unobtrusive-ajax.js is correctly loaded in the page and check the name of your productcode in the input tag (should be equal of the action parameter).

Let me know if this solves your problem.

Upvotes: 0

COLD TOLD
COLD TOLD

Reputation: 13579

Make sure you reference MS files

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

also I think you looking to post and not get.

Upvotes: 1

Related Questions