![](/img/trans.png)
[英]mvc PartialView with Dialog Partial View showing html
[英]MVC Ajax Partial View call returns partialview site without “parent”
我通过Ajax在部分重新加载页面上工作。 这就是我所拥有的:
控制器:
public class EmailController : Controller
{
//
// GET: /Email/
[Authorize]
public ActionResult Index(string id)
{
//.. Some Code here to get my Email List
return View(emails);
}
[Authorize]
public PartialViewResult EmailPartial(string id = "1,2")
{
//.. Some Code here to get my Email List with the new filter
return PartialViewResult(emails);
}
}
主视图:
@model IEnumerable<namespace.Emailgesendetview>
@{
ViewBag.Title = "Index";
AjaxOptions ajaxOpts = new AjaxOptions
{
UpdateTargetId = "emailBody"
};
Layout = "~/Views/Shared/_Default.cshtml";
}
// .... uninteresting html code
<div id="emailBody">
@Html.Action("EmailPartial", new { selectedRole = Model })
</div>
// .... uninteresting html code
// Here comes my action link:
<li>
@Ajax.ActionLink("martin",
"EmailPartial",
"Email",
new { id = "3"},
new AjaxOptions()
{
HttpMethod = "GET",
AllowCache = false,
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "emailBody"
})
</li>
部分视图:
@model IEnumerable<namespace.Emailgesendetview>
<div class="mail-body">
<ul class="mail-list">
@{
foreach (var userMail in Model)
{
//... Code vor showing the models
}
}
</ul>
</div>
如果我现在单击链接,他将启动以下功能:EmailPartial,但他没有添加(或替换我都尝试了)该内容。 他单独打开EmailPartial视图吗?
在这篇文章中: 如何通过对控制器的Ajax调用在MVC5中呈现部分视图并返回HTML ,部分函数不是PartialViewResult,而是ActionResult,但是我已经尝试过了。
太好了,我可以告诉我我的错误或误解。
非常感谢,祝您有美好的一天:)
由于您尚未在视图或布局中包含jquery-unobtrusive-ajax.js,因此可以正常重定向。 – 3月31日,Stephen Muecke在10:30
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.