MVC3 ASPX ViewBag /型号 [英] MVC3 ASPX ViewBag / Model

查看:111
本文介绍了MVC3 ASPX ViewBag /型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用模型的视图

 继承=System.Web.Mvc.ViewPage< Program.Models.Test>中

我在视图中使用显示数据:

 > <%= this.Model.Item == NULL? :
> Html.GetString(this.Model.Item.Name)%GT;

现在我想上显示来自相同的看法另一个模型不同的项目,我想ViewBag也许会有帮助,所以在我CONTROLER,我说:

  ViewBag.GuideLines = ctx.GuideLines;

我的问题是,我可以在同一个视图中显示来自指引模型的特定项目价值?

先谢谢了。


解决方案

  

我想ViewBag可能会帮助


错误思想。 ViewBag / ViewData的永远的帮助。我从来没有使用这些2中的任何ASP.NET MVC应用程序。


  

现在我想从同一个视图另一种模式

显示不同的项目

只需添加这其他模型作为主视图模型的财产。所以,你将有 Model.Guidelines 在视图中。

I have a view that is using a model

Inherits="System.Web.Mvc.ViewPage<Program.Models.Test>"

I am displaying data in the view using:

> <%= this.Model.Item == null ? "" :
> Html.GetString(this.Model.Item.Name) %>

Now I am trying to display a different item from another model on the same view, I thought ViewBag might help, so in my controler, I added:

ViewBag.GuideLines = ctx.GuideLines;

My question is can I display a specific item value from Guidelines model on the same view?

Thanks in advance.

解决方案

I thought ViewBag might help

Wrong thought. ViewBag/ViewData never helps. I never use those 2 in any ASP.NET MVC application.

Now I am trying to display a different item from another model on the same view

Simply add this other model as property of the main view model. So you will have Model.Guidelines in the view.

这篇关于MVC3 ASPX ViewBag /型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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