Html.Partial() 跳过控制器动作 [英] Html.Partial() skips the controller action
问题描述
我正在使用@Html.Partial("Index") 调用控制器中名为Index"的操作,然后该操作应返回Index"视图.不幸的是,看起来控制器操作被忽略了,因为我在索引视图中收到一个错误,即模型为空.我尝试在控制器操作中设置断点,但它们只是被跳过,似乎在不读取控制器的情况下呈现视图索引"?这是怎么回事?
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?
感谢您的任何想法.
控制器操作代码如下:
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
只会渲染一个视图.如果要调用操作,则必须使用 Html.Action
,它将执行操作并返回视图(如果有).
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屋!