Html.Partial()跳过控制器动作 [英] Html.Partial() skips the controller action

查看:452
本文介绍了Html.Partial()跳过控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用@ Html.Partial(「指数」)呼吁索引,在控制器的操作,那么它应该返回我的索引视图来调用。不幸的是,它看起来像控制器动作,是因为我得到了指数的错误查看型号为NULL忽略。我试图在控制器动作设置断点,他们只是被跳过,似乎认为指数是不读控制器呈现?这到底是怎么回事呢?

THX的任何想法。

控制器动作code是如下:

 公众的ActionResult指数()
{
        INT用户ID =(int)的会议[用户ID];
        变种照片= db.Photos
                    。凡(照片=> Photo.ClientId ==用户ID)
                    .ToList();
        如果((布尔)会议[管理员] ==真)返回PartialView(组图)
        否则返回查看(组图)
}


解决方案

<一个href=\"http://msdn.microsoft.com/en-us/library/ee402898%28v=vs.100%29.aspx\"><$c$c>Html.Partial只会渲染视图。如果你想叫一个动作,你必须使用<一个href=\"http://msdn.microsoft.com/en-us/library/ee728618%28v=vs.100%29.aspx\"><$c$c>Html.Action,将执行的动作和返回,如果任何视图。

I am using @Html.Partial("Index") to call upon an action called "Index" in a controller, which should then return me the "Index" view. Unfortunately, it looks like the controller action is ignored because I get an error in Index view that Model is null. I tried setting breakpoints in the controller action and they are simply being skipped, it seems that the view "Index" is rendered without reading the controller? What is going on here?

Thx for any ideas.

Controller Action code is below:

public ActionResult Index()
{
        int UserId = (int)Session["UserId"];
        var Photos = db.Photos
                    .Where(Photo => Photo.ClientId == UserId)
                    .ToList();
        if ((bool)Session["Admin"] == true) return PartialView(Photos);
        else return View(Photos);
}

解决方案

Html.Partial will only render a view. If you want to call an action you must use Html.Action, which will execute the action and return the view if any.

这篇关于Html.Partial()跳过控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆