C# MVC Ajax局部视图调用返回不带“";“家长”;

C# MVC Ajax局部视图调用返回不带“";“家长”;,c#,.net,ajax,asp.net-mvc,C#,.net,Ajax,Asp.net Mvc,我通过Ajax开发了一个部分重新加载页面。 这就是我所拥有的: 控制器: public class EmailController : Controller { // // GET: /Email/ [Authorize] public ActionResult Index(string id) { //.. Some Code here to get my Email List

我通过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
@{
ViewBag.Title=“Index”;
AjaxOptions ajaxOpts=新的AjaxOptions
{
UpdateTargetId=“emailBody”
};
Layout=“~/Views/Shared/_Default.cshtml”;
}
// .... 无趣html代码
@Action(“EmailPartial”,新的{selectedRole=Model})
// .... 无趣html代码
//下面是我的行动链接:
  • @ActionLink(“martin”, “电子邮件部分”, “电子邮件”, 新的{id=“3”}, 新的AjaxOptions() { HttpMethod=“GET”, AllowCache=false, InsertionMode=InsertionMode.Replace, UpdateTargetId=“emailBody” })
  • 局部视图:

    @model IEnumerable<namespace.Emailgesendetview>   
    <div class="mail-body">
        <ul class="mail-list">
            @{
                foreach (var userMail in Model)
                {
                    //... Code vor showing the models
                }
            }
        </ul>
    </div>
    
    @model IEnumerable
    
      @{ foreach(模型中的var userMail) { //…显示模型的代码 } }
    如果我现在点击链接,他会启动函数:EmailPartial,但他没有添加(或替换我尝试过的两个)内容。他一个人打开部分视图

    在本帖中: 分部函数不是一个PartialViewResult,它是一个ActionResult,但我已经尝试过了

    如果你能告诉我我的错误或失误,那就太好了


    非常感谢,祝您度过愉快的一天:)

    因为您的视图或布局中没有包含jquery-unobtrusive-ajax.js,所以这是一个正常的重定向Stephen Muecke 3月31日10:30

    为什么要在函数参数中赋值?EmailPartial(string id=“1,2”)听起来像是执行了标准get,脚本中可能缺少jquery.unobtrusive.js。这就是在Mvcto中连接Ajax函数的原因。要确保我的列表中有一个值,如果页面加载时没有Ajax调用,我希望获得索引为1和2:)的邮件,因为您的视图或布局中没有包含
    jquery unobtrusive Ajax.js
    ,因此这是正常的重定向。