如何在Html.RenderAction(MVC3)中发送模型对象 [英] How to send model object in Html.RenderAction (MVC3)

查看:82
本文介绍了如何在Html.RenderAction(MVC3)中发送模型对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC3剃须刀,并且试图将对象传递到局部视图,但它不起作用.

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屋!

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