Asp.net mvc 4 mvc:当索引页面已经加载时,单击按钮即可使用相同的webgrid显示数据
下面的代码从数据库中提取数据,返回viewmodel并填充webgrid。 在视图上,有一个下拉列表和旁边的一个按钮 我希望我的用户从下拉列表中选择任何项目,然后单击按钮进行搜索 用于使用所选项目的数据 我想重用webgrid来显示数据。我想我需要在点击 按钮 如何做到这一点,以便再次使用webgridAsp.net mvc 4 mvc:当索引页面已经加载时,单击按钮即可使用相同的webgrid显示数据,asp.net-mvc-4,Asp.net Mvc 4,下面的代码从数据库中提取数据,返回viewmodel并填充webgrid。 在视图上,有一个下拉列表和旁边的一个按钮 我希望我的用户从下拉列表中选择任何项目,然后单击按钮进行搜索 用于使用所选项目的数据 我想重用webgrid来显示数据。我想我需要在点击 按钮 如何做到这一点,以便再次使用webgrid public ActionResult Index() { string phyLocationName
public ActionResult Index()
{
string phyLocationName = string.Empty;
string extractPhylocationcode = string.Empty;
var currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
Edmviewmodel objedmtest = new Edmviewmodel();
if (currentUser != null)
{
try
{
string cleanedCurrentUser = currentUser.Substring(5);
SearchActiveDirectory obj = new SearchActiveDirectory();
phyLocationName = obj.GetLocationCode(cleanedCurrentUser);
extractPhylocationcode = phyLocationName.Substring(0, 3);
//Use my viewmodel to get all data
objedmtest = _edmDataService.GetRequiredData(extractPhylocationcode);
objedmtest.BranchesSetup.selectedbranch = phyLocationName;
}
catch (Exception ex)
{
//logger.Error(ex);
}
}
return View(objedmtest);
}
我已经在我的viewmodel中获得了webgrid所需的数据,这是下面这一行。我还需要另一个吗
public List<Catalogorder> GetCatDataByLocation { get; set; }
public class Edmviewmodel
{
public Setupbranches BranchesSetup { get; set; }
public List<Catalogorder> GetCatDataByLocation { get; set; }
public List<SelectListItem> GetRouteByBranch { get; set; }
}
公共列表GetCatDataByLocation{get;set;}
公共类模型
{
公共设置分支分支设置{get;set;}
公共列表GetCatDataByLocation{get;set;}
公共列表GetRouteByBranch{get;set;}
}
以下是一个框架,介绍了如何通过代码重用实现这一点(不必复制代码来渲染网格) Edmviewmodel
List<WebgridItems> Items { get; set; }
看法
栅格局部视图
@model List<WebgridItems>
foreach(var item in Model)
render grid row
@型号列表
foreach(模型中的var项目)
渲染网格行
现在是Ajax调用
控制器
Index()
Get the Items and build the Edmviewmodel
View(Edmviewmodel)
IndexGrid(int filterItem)
var vm = Get the List<WebgridItems> using the filterItem
return PartialView("Grid, vm)
IndexGrid(int-filterItem)
var vm=使用filterItem获取列表
返回PartialView(“网格,虚拟机)
客户端
选择下拉项并单击按钮后,使用filterItem调用
IndexGrid
。将网格替换为生成的HTML。谢谢。对此我不是很清楚。我需要创建一个局部视图,对吗?是的,这将负责渲染网格,因此网格的模型只是项目列表。它将用于索引视图和进行ajax调用时。我添加了我的viewmodel。
IndexGrid(int filterItem)
var vm = Get the List<WebgridItems> using the filterItem
return PartialView("Grid, vm)