[英]Grid.MVC Single view for CRUD operations
I am using Grid.MVC( https://gridmvc.codeplex.com/ ) and I need to render a grid and CRUD for the grid in the same view. 我正在使用Grid.MVC( https://gridmvc.codeplex.com/ ),并且需要在同一视图中渲染网格和该网格的CRUD。
@model IEnumerable<Grid.Models.Catagory>
...
...
@Html.Grid(Model).Columns(columns =>
{
columns.Add()
.Encoded(false)
.Sanitized(false)
.Titled("CatagoryName").RenderValueAs(o => RenderCatagoryName("CatagoryName", o.CatagoryName));
columns.Add()
.Encoded(false)
.Sanitized(false)
.Titled("Color").RenderValueAs(o => RenderCatagoryName("Color", o.Color));
columns.Add()
.Encoded(false)
.Sanitized(false)
.Titled("Print Template").RenderValueAs(o => RenderCatagoryName("Print Template", o.PrintTemplate));
}
My controller 我的控制器
public ActionResult Index()
{
return View(clients);
}
This works fine, but when I need to do an insert in that same view, I am unable to use the same model since it is an IEnumerable type. 这可以正常工作,但是当我需要在同一视图中进行插入时,由于它是IEnumerable类型,因此无法使用同一模型。
--Insert values--
//couldn't use the model for insert directly since it is a list type
@Html.LabelFor(m => m.)
@Html.TextBoxFor(m => m., new { maxlength = 50 })
My ViewModel 我的ViewModel
public class Catagory
{
public int CatagoryID { get; set; }
public string CatagoryName { get; set; }
public string Color { get; set; }
public string PrintTemplate { get; set; }
public string Language { get; set; }
}
Is there any way to use the same view for both the Grid.MVC and insert operations 有没有办法对Grid.MVC和插入操作使用相同的视图
make the list of Catagory
(btw it's spelled 'Category') be a property of a new view model. 将
Catagory
列表(顺便说一下“ Category”分类)作为新视图模型的属性。
public class MyViewModel
{
public Category CategoryToInsert { get; set; }
public IEnumerable<Category> CategoriesToShow { get; set; }
}
View: 视图:
@model MyViewModel
...
...
@Html.Grid(Model.Categories).Columns(columns =>
...
@* Insert form: *@
@Html.LabelFor(m => m.CategoryToInsert.CategoryName)
@Html.TextBoxFor(m => m.CategoryToInsert.CategoryName, new { maxlength = 50 })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.