简体   繁体   English

MVC Ajax Partial View调用返回不带“父”的partialview网站

[英]MVC Ajax Partial View call returns partialview site without “parent”

i worked on a partial reload page via Ajax. 我通过Ajax在部分重新加载页面上工作。 This is what i have: 这就是我所拥有的:

Controller: 控制器:

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);
        }
    }

Main View: 主视图:

@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>

Partial View: 部分视图:

@model IEnumerable<namespace.Emailgesendetview>   
<div class="mail-body">
    <ul class="mail-list">
        @{
            foreach (var userMail in Model)
            {
                //... Code vor showing the models
            }
        }
    </ul>
</div>

If i click on the link now, he starts the function: EmailPartial, but he didn't add (or replace i tryed both) the content. 如果我现在单击链接,他将启动以下功能:EmailPartial,但他没有添加(或替换我都尝试了)该内容。 He Opens the EmailPartial view alone?! 他单独打开EmailPartial视图吗?

In this post: How to render partial view in MVC5 via ajax call to a controller and return HTML the Partial function is not a PartialViewResult it's a ActionResult, but i already tryd that. 在这篇文章中: 如何通过对控制器的Ajax调用在MVC5中呈现部分视图并返回HTML ,部分函数不是PartialViewResult,而是ActionResult,但是我已经尝试过了。

Would be great i you could show me my error or misstake. 太好了,我可以告诉我我的错误或误解。

Thanks a lot and have a nice day :) 非常感谢,祝您有美好的一天:)

Because you have not included jquery-unobtrusive-ajax.js in your view or layout so its making a normal redirect. 由于您尚未在视图或布局中包含jquery-unobtrusive-ajax.js,因此可以正常重定向。 – Stephen Muecke Mar 31 at 10:30 – 3月31日,Stephen Muecke在10:30

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM