如何在mvc中使用不同的模型填充下拉列表 [英] How to populate a dropdown list using different model in mvc

查看:62
本文介绍了如何在mvc中使用不同的模型填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个View和一个与之对应的模型。我的问题是我想在视图中使用同一视图中的不同模型填充下拉列表。我寻求你的帮助

I have a View and a Model corresponding to it.My problem is I want to populate drop downlist in the view using a different model in the same view.I seek your help

推荐答案

使用Viewbag

as



use Viewbag
as

public ActionResult PPEntry()
       {
           ViewBag.ddlData = new FillMaster().GetddList();
           //your model code
           return View(model);
       }





在您的视图中





in your View

Select Block <select id="ddlMaster">
           @foreach (var item in ViewBag.ddlData)
           {
               <option value="@item.ID">@item.STATE</option>
           }
       </select>


由于Model只是一个类..您可以在View中使用当前Model中的那个类属性并使用它其他模型类属性在您的下拉列表中指定值..

希望这有助于..!
As the Model is only a class.. You can use that class property inside you current Model which you are referring in the View and use that other model class property to assign the values in your drop down..
Hope this helps..!


这篇关于如何在mvc中使用不同的模型填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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