我在网上看了很多类似的问题,但仍然无法弄清楚问题所在。我的 Ajax.BeginForm
通过 Controller
中的 PartialView
返回一条消息,但字符串替换了整个页面。
查看
:
@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>
我的 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>
我在 _Layout.cshtml
中引用了 jquery.unobtrusive-ajax.js
文件,所以这似乎不是原因。
有谁知道为什么消息会替换整个页面?
最佳答案
确保引用 MS 文件
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
我还认为您是想发帖而不是收到。
关于c# - Ajax.BeginForm 替换整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29974346/