ویرایش قالب پیش فرض Add View در ASP.NET MVC برای سازگار سازی آن با Twitter bootstrap
نویسنده: وحید نصیری
تاریخ: ۱۳۹۲/۰۳/۲۱ ۸:۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
PM> Install-Package Mvc4CodeTemplatesCSharp
<#
if (!mvcHost.IsContentPage) {
#>
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<#
}
}
#>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true, null, new { @class = "alert alert-error alert-block" })
<fieldset class="form-horizontal">
<legend><#= mvcHost.ViewDataType.Name #></legend>
<#
foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
if (!property.IsPrimaryKey && !property.IsReadOnly && property.Scaffold) {
#>
<div class="control-group">
<#
if (property.IsForeignKey) {
#>
@Html.LabelFor(model => model.<#= property.Name #>, "<#= property.AssociationName #>",new {@class="control-label"})
<#
} else {
#>
@Html.LabelFor(model => model.<#= property.Name #>,new {@class="control-label"})
<#
}
#>
<div class="controls">
<#
if (property.IsForeignKey) {
#>
@Html.DropDownList("<#= property.Name #>", String.Empty)
<#
} else {
#>
@Html.EditorFor(model => model.<#= property.Name #>)
<#
}
#>
@Html.ValidationMessageFor(model => model.<#= property.Name #>,null,new{@class="help-inline"})
</div>
</div>
<#
}
}
#>
<div class="form-actions">
<button type="submit" class="btn btn-primary">ارسال</button>
<button class="btn">لغو</button>
</div>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<#
if(mvcHost.IsContentPage && mvcHost.ReferenceScriptLibraries) {
#>
@section JavaScript {
} public class MyModel
{
public Person person { get; set; }
public string Type{ get; set; }
}
public class Person
{
Public string FirstName{get;set;}
public string LastName{get;set;}
}@model myModel
@{
ViewBag.Title = "View3";
}
<h2>View3</h2>
@using (Ajax.BeginForm() {
<section class="Simple Page">
<div class="row-fluid">
@Html.LabelFor(model => model.Type, new { @class = "span3" })
<div class="input-control text span4">
@Html.EditorFor(model => model.Type, new { @class = "span4 ", placeholder = Html.Encode("ResorceName") })
</div>
</div>
</section>
}Compiling transformation: The type or namespace name 'MvcTextTemplateHost' could not be found (are you missing a using directive or an assembly reference?)
PM> Install-Package Mvc5CodeTemplatesCSharp -Version 5.0.0