Asp.net mvc mvc将元组数据作为参数传递
我有一个像这样的模型Asp.net mvc mvc将元组数据作为参数传递,asp.net-mvc,tuples,Asp.net Mvc,Tuples,我有一个像这样的模型 @model Tuple<Urun,List<UrunKatagori>> 还有我的控制器 [HttpPost] public ActionResult Guncelle (Urun Urun){ Urun_BLL urun_bll = new Urun_BLL(); // urun_bll.Update(mdl); X.Msg.Notify(new NotificationConfig {
@model Tuple<Urun,List<UrunKatagori>>
还有我的控制器
[HttpPost]
public ActionResult Guncelle (Urun Urun){
Urun_BLL urun_bll = new Urun_BLL();
// urun_bll.Update(mdl);
X.Msg.Notify(new NotificationConfig
{
Icon = Icon.Accept,
Title = "Working",
Html =Urun.Ad.ToString()//I need to get data here
}).Show();
return this.Direct();
}
我强烈建议您创建一个viewmodel类,而不是传递一个
元组
public class GuncelleViewModel
{
public Urun Urun { get ;set; }
public List<UrunKatagori>> UrunKatagori { get; set; }
}
在视图中,使用以下模型
@model GuncelleViewModel
使用与视图文件(*.cshtml)一对一关联的viewmodel类是一个非常好的实践。它可以帮助您保持设计的整洁和更灵活,而不是传递特定的数据类型,例如Tuple
[HttpPost]
public ActionResult Guncelle (Urun Urun)
{
Urun_BLL urun_bll = new Urun_BLL();
// urun_bll.Update(mdl);
X.Msg.Notify(new NotificationConfig
{
Icon = Icon.Accept,
Title = "Working",
Html =Urun.Ad.ToString()//I need to get data here
}).Show();
var viewModel = new GuncelleViewModel()
viewModel.Urun = Urun;
viewModel.UrunKatagori = // TODO - However you get the categories.
return View(viewModel);
// this.Direct(); What does this.Direct() do? Replace it with calling the view instead, much cleaner.
}
@model GuncelleViewModel