问题描述
我在Mvc4工作,我想将页面重定向到选定的下拉值,我在下面使用通过视图模型的下拉菜单
public ActionResult Create()
{
var Complain = new ComplainViewModel()
{
Countries = new SelectList(db.Countries,Id,Name ,0),
EffectedStates = new SelectList(db.States,Id,Name,null),
EffectedCities = new SelectList(db.Cities, Id,Name,null),
EffectedAreas = new SelectList(db.EffectedArea,Id,Name,null),
Types = new SelectList (db.Type,Id,Name,0),
};
返回查看(投诉);
}
//
// POST:/ ComplainView / Create
[AllowAnonymous]
[HttpPost]
public ActionResult Create(ComplainViewModel抱怨)
{
试试
{
complain.Comp.country = db.Countries.Find(complain.CountryId);
complain.Comp.State = db.States.Find(complain.States);
complain.Comp.City = db.Cities.Find(complain.Cities);
complain.Comp.Area = db.EffectedArea.Find(complain.Areas);
complain.Comp.ComplainType = db.Type.Find(complain.TypeId);
投诉CV = db.Complains.Add(抱怨.Comp);
db.SaveChanges();
I am working in Mvc4 and I want to redirect the page to the selected value of drop down where i am using dropdown through view model
public ActionResult Create()
{
var Complain = new ComplainViewModel()
{
Countries = new SelectList(db.Countries, "Id", "Name", 0),
EffectedStates = new SelectList(db.States, "Id", "Name", null),
EffectedCities = new SelectList(db.Cities, "Id", "Name", null),
EffectedAreas = new SelectList(db.EffectedArea, "Id", "Name", null),
Types = new SelectList(db.Type, "Id", "Name", 0),
};
return View(Complain);
}
//
// POST: /ComplainView/Create
[AllowAnonymous]
[HttpPost]
public ActionResult Create(ComplainViewModel complain)
{
try
{
complain.Comp.country = db.Countries.Find(complain.CountryId);
complain.Comp.State = db.States.Find(complain.States);
complain.Comp.City = db.Cities.Find(complain.Cities);
complain.Comp.Area = db.EffectedArea.Find(complain.Areas);
complain.Comp.ComplainType = db.Type.Find(complain.TypeId);
Complain CV = db.Complains.Add(complain.Comp);
db.SaveChanges();
这篇关于通过MVC4中下拉列表的选定值重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!