This question is locked. New answers and comments are not allowed.
I've done a custom template.
On edit mode, the model is not bind for Html.DisplayFor method.
Html.EditorFor works ans binds dynamically
What should i do to access to the data model ?
@Model is not bind
Thanks a lot for your help
=============== MyForm ==============
@model TestTelerik.Models.MyData
<h1>Ma custom form</h1>
data
is
@Html.DisplayFor(m => m.ProductName)
==========================================
@(Html.Telerik().Grid<TestTelerik.Models.MyData>()
.Name(
"MyData"
)
.ToolBar(command => command.Insert().ButtonType(GridButtonType.ImageAndText))
.DataKeys(keys => keys.Add(p => p.ProductID))
.DataBinding(dataBinding => dataBinding.Ajax()
.Insert(
"AddNew"
,
"Home"
)
.Update(
"Update"
,
"Home"
)
.Select(
"Select"
,
"Home"
))
.Columns(columns => {
columns.Bound(p => p.ProductID).Width(50);
columns.Bound(p => p.ProductName).Width(200); ;
columns.Command(commands => { commands.Edit(); }).Width(50);
})
.Editable(editing => editing.Mode(GridEditMode.InForm).TemplateName(
"MyForm"
))
)
============ Controller ============
public
class
HomeController : Controller
{
public
ActionResult Index()
{
return
View(MyData.g_datas);
}
[GridAction]
public
ActionResult Select()
{
return
View(
new
GridModel(MyData .g_datas));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public
ActionResult AddNew(MyData oData)
{
if
(ModelState.IsValid)
{
MyData.g_datas.Add(
new
MyData () { ProductID = oData.ProductID, ProductName = oData.ProductName });
}
return
View(
new
GridModel(MyData.g_datas));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public
ActionResult Update(MyData oData)
{
return
View(
new
GridModel(MyData .g_datas));
}
}
=========== MODEL ======================
[Serializable]
public
class
MyData
{
public
int
ProductID {
get
;
set
; }
[Required ]
[DataType(DataType .Text)]
public
String ProductName {
get
;
set
;}
public
static
List<MyData> g_datas =
new
List<MyData>{
new
MyData() {ProductID = 1, ProductName =
"magic product"
},
new
MyData() {ProductID = 2, ProductName =
"super product"
}};
}