i am new to MVC 5.0 and i am creating an application using MVC 5.0 with entity framework 6.0 and scaffolding templates and controllers . i want to create custom templates using kendo ui grid for example to show the data from my database.
i followed this example : How to create custom scaffold templates in ASP.NET MVC5?
but i did not manage to find out how to create custom views. my new view templates are nowhere and i can not choose them.
i saw that in MVC 4 and older versions it was a different aproach about using or creating custom themes.
can anybody help me about the procces ?
I don't know if this will work in MVC5, but I've had success in MVC3 by adding the templates to my project:
MyProject
|
-- CodeTemplates
|
+- AddController
| |
| +- Controller.tt
| -- ControllerWithContext.tt
|
-- AddView
|
-- CSHTML
|
+- Create.tt
+- Delete.tt
+- Details.tt
+- Edit.tt
+- Empty.tt
-- List.tt
If this works in MVC5, let me know. Also, putting the templates here makes them available to everyone on the development team, a definite plus for us.
See the Accepted Answer Custom Scaffolding Templates in Visual Studio 2013 for more details.
I had your problem yesterday and I found this link . The below script must insert into T4 template file.
<script>
$(document).ready(function () {
setTimeout(function () {
$("#MYGRID").kendoGrid({
dataSource: {
type: "json",
transport: {
read: "/GetJsonData"
},
schema: {
model: {
fields: {
item1:{type:"string"},
item2:{type:"string"},
item3:{type:"string"}
}
}
},
pageSize: 10
},
columns: [{
field:"Id",
filterable: false
},
"Column2",
"Column3"
]
});
});
});
</script>
Update: I customize the MVC grid in T4 template for Kendo grid:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
<# IEnumerable < PropertyMetadata > properties = ModelMetadata.Properties;
foreach (PropertyMetadata property in properties)
{
if (property.Scaffold && !property.IsPrimaryKey && !property.IsForeignKey)
{
#>
<#
// We do not want to show any association properties for which there is
// no associated foreign key.
if (property.IsAssociation && GetRelatedModelMetadata(property) == null)
{
continue;
}
#>
columns.Bound(model => model.<#= GetValueExpression(property) #>);
<#}
}#>
.columns.Bound(item =>
@item.objectId).Title("title").Filterable(false).Groupable(false);
})
.DataSource(dataSource => dataSource
.Server
.Model(model => model.Id(item => item.objectId))
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.