表格和网格在同一页面mvc3 [英] Form and Grid in same page mvc3
本文介绍了表格和网格在同一页面mvc3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带保存按钮的客户输入表格。我想保存客户的信息,并希望在同一页面的网格中显示信息。保存后,此网格将自动刷新并加载数据。但无法在同一视图中实现网格内容。那我怎么能在同一页面中使用表格和网格???需要帮助。
Hi,
I have a customer entry form with save button.I want to do save the information of customer and want to show info in a grid in the same page. after saving this grid will auto refresh and load data. But could not implement the grid stuff in same view. So how can i use form and grid in same page??? Need help.
推荐答案
创建一个ViewModel例如
Create a ViewModel for example
public class SampleViewModel
{
public int Id{get;set;}
public string Name{get;set;}
public List<customer> Customers{get;set;}
}</customer>
//您的加载索引如下所示
//Your loading index look like this
public ActionResult Index()
{
List<customers> customers=//do the logic here for loading the collection you want;
var viewModel=new SampleViewModel();
viewModel.Customers=customers;
return View(viewModel);
}
//Create action when click save.
[HttpPost]
public ActionResult Create(SampleViewModel viewModel)
{
}</customers>
在视图返回模型中为 @model SampleViewModel
希望这有助于
in the view return model as @model SampleViewModel
Hope this helps
只需在此代码段中执行一项操作
Just do one thing in this code snippet
public ActionResult Index()
{
List<customers> customers=//do the logic here for loading the collection you want;
var viewModel=new SampleViewModel();
viewModel.Customers=customers;
return View(viewModel);
}
//Create action when click save.
[HttpPost]
public ActionResult Create(SampleViewModel viewModel)
{
List<customers> customers=//do the logic here for loading the collection you want;
var viewModel=new SampleViewModel();
viewModel.Customers=customers;
return View(viewModel);</customers>
}
}
这篇关于表格和网格在同一页面mvc3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文