asp.net-mvc – ASP.NET MVC – 查看多个模型
发布时间:2020-12-15 19:10:42 所属栏目:asp.Net 来源:网络整理
导读:我试图生成这样的HTML form action="/some/process" method="post" input type="hidden" name="foo.a" value="aaa"/ input type="hidden" name="bar.b" value="bbb"/ input type="submit" / /form 所以它可以通过这个动作处理: public ActionResult Process
我试图生成这样的HTML
<form action="/some/process" method="post"> <input type="hidden" name="foo.a" value="aaa"/> <input type="hidden" name="bar.b" value="bbb"/> <input type="submit" /> </form> 所以它可以通过这个动作处理: public ActionResult Process(Foo foo,Bar bar) { ... } 给出Action代码 public ActionResult Edit() { ViewData["foo"] = new Foo { A = "aaa" }; ViewData["bar"] = new Bar { B = "bbb" }; return View(); } 我应该在Edit.aspx视图中写什么?我不想手动写名字’foo.a’和’bar.b’。 解决方法
字符串索引ViewData是坏的。你可能想要做的是为你的多变量视图数据做一个小包装类,并传递给一个强类型视图。 IE:
public class FooBarViewData { public Foo Foo {get; set;} public Bar Bar {get; set;} } public ActionResult Edit() { FooBarViewData fbvd = new FooBarViewData(); fbvd.Foo = new Foo(){ A = "aaa"}; fbvd.Bar = new Bar(){ B = "bbb"}; return View(fbvd); } 然后你的视图只是强烈打字为FooBarViewData,你可以使用Model属性调用该对象的成员。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- HttpHandler无法在ASP.NET MVC3 Web应用程序中工作
- asp.net – 如何从列表框中获取所选项目valus而不使用for循
- 在控件asp.net之间动态添加
- .net – 将数据写入App_Data
- asp.net-mvc – Ext.NET没有与ASP.NET MVC 4集成
- asp.net – VS 2012发布:找不到有效的AspnetMergePath
- entity-framework – 数据层中的IdentityUser
- asp.net-mvc-3 – 模型绑定器究竟做了什么?如何有效地使用
- asp.net-mvc – 我的web.config中没有角色管理器部分定义
- asp.net-mvc – Viewmodel和动态菜单最佳实践 – ASP.NET M
推荐文章
站长推荐
热点阅读