簡體   English   中英

MVC Ajax Partial View調用返回不帶“父”的partialview網站

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM