如何在 Html.RenderAction (MVC3) 中发送模型对象 [英] How to send model object in Html.RenderAction (MVC3)
问题描述
我正在使用 MVC3 razor,我试图将一个对象传递给局部视图,但它不起作用.
I'm using MVC3 razor, and I'm trying to pass an object to a partial view, and it's not working.
无需将对象模型发送到局部视图即可正常工作:
This works fine without sending the object model to the partial view:
Html.RenderAction("Index", "ViewName");
尝试这不会发送模型对象,而是得到空值(对象有数据,而视图需要它):'
Trying this doesn't sent the model object, i'm getting nulls instead (the object has data, and the view expects it):'
Html.RenderAction("Index", "ViewName", objectModel);
这甚至可以使用 RenderAction 吗?
Is this even possible using RenderAction?
谢谢!
我发现了错误,控制器的动作有一个错误,没有接收到发送的对象.感谢您的帮助!
I found the error, there was an error with the controller's action that didn't pick up the sent object. Thanks for all your help!
推荐答案
说你想通过 foo
作为模型,让它先
say you want to pass foo
as model, make it first
public class Foo {
public string Name { get; set; }
public int Age { get; set; }
}
现在创建一个 ActionResult
now make an ActionResult
public ActionResult FooBar(Foo _foo){
return PartialView(_foo);
}
叫它
@Html.RenderAction("FooBar", "Controller", new { Name = "John", Age=20 });
这篇关于如何在 Html.RenderAction (MVC3) 中发送模型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!