本文介绍了如何从MVC动作的下拉列表中获取多个属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mvc操作中的单个下拉列表获取多个属性值,但我无法通过单个下拉列表获取复杂数据。

请提供任何解决方案。

您的反馈意见将不胜感激。



我的尝试:



公共类ViewModelMain

{

public ViewModelSubfunctiona Drp {get;组; }



public List< viewmodelsubfunctiona> ListFunc {get;组; }

}



公共类ViewModelSubfunctiona

{

public int Id { get; set;}

public string Name {get; set;}

public int FuncId {get; set;}

}





[HttpGet]

公共ActionResult索引()

{

var data = GetList();



ViewModelMain model = new ViewModelMain();

model.ListFunc = data;

返回查看(型号);

}



[HttpPost]

公共ActionResult索引(ViewModelMain模型)

{



返回查看();

}



public List< ViewModelSubfunctiona> GetList()

{

List< ViewModelSubfunctiona> _list = new List< ViewModelSubfunctiona>();

_list.Add(new ViewModelSubfunctiona {Id = 1,Name =A,FuncId = 1});

_list .Add(new ViewModelSubfunctiona {Id = 2,Name =B,FuncId = 1});

_list.Add(new ViewModelSubfunctiona {Id = 3,Name =C,FuncId = 1 });

_list.Add(new ViewModelSubfunctiona {Id = 4,Name =D,FuncId = 2});

_list.Add(new ViewModelSubfunctiona {Id = 5,Name =E,FuncId = 2});

_list.Add(new ViewModelSubfunctiona {Id = 6,Name =F,FuncId = 2});

返回_list;

}





查看:@model Test.Controllers.ViewModelMain

@ Html.DropDownListFor(x => x.Drp,new SelectList(Model.ListFunc,Id,Name),,new {@ maxlength =20,@ style =})

I am trying to fetch multiple attribute value with single drop down list in mvc action but i am not able to fetch complex data with single drop down list.
Please provide any solution.
Your feedback will be appreciated.

What I have tried:

public class ViewModelMain
{
public ViewModelSubfunctiona Drp { get; set; }

public List<viewmodelsubfunctiona> ListFunc { get; set; }
}

public class ViewModelSubfunctiona
{
public int Id{get;set;}
public string Name{get;set;}
public int FuncId{get;set;}
}


[HttpGet]
public ActionResult Index()
{
var data = GetList();

ViewModelMain model = new ViewModelMain();
model.ListFunc = data;
return View(model);
}

[HttpPost]
public ActionResult Index(ViewModelMain model)
{

return View();
}

public List<ViewModelSubfunctiona> GetList()
{
List<ViewModelSubfunctiona> _list = new List<ViewModelSubfunctiona>();
_list.Add(new ViewModelSubfunctiona { Id = 1, Name = "A", FuncId = 1 });
_list.Add(new ViewModelSubfunctiona { Id =2, Name = "B", FuncId = 1 });
_list.Add(new ViewModelSubfunctiona { Id = 3, Name = "C", FuncId = 1 });
_list.Add(new ViewModelSubfunctiona { Id = 4, Name = "D", FuncId = 2 });
_list.Add(new ViewModelSubfunctiona { Id = 5, Name = "E", FuncId = 2 });
_list.Add(new ViewModelSubfunctiona { Id = 6, Name = "F", FuncId =2 });
return _list;
}


View:@model Test.Controllers.ViewModelMain
@Html.DropDownListFor(x => x.Drp, new SelectList(Model.ListFunc,"Id","Name"),"", new { @maxlength="20", @style="" })

推荐答案


这篇关于如何从MVC动作的下拉列表中获取多个属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 20:04