_ViewStart.cshtml部分根本不起作用。以下是输出
<input type="text" value="{ class = big-field, tabindex = 1 }" name="Chris" id="Chris">
的 // Edit.aspx 的
@model myproject.Web.Models.ViewModel.User.EditViewModel
@{
View.Title = "Edit Profile";
Func<myproject.Web.Models.ViewModel.User.EditViewModel, HelperResult> lst = ViewContext.Controller.ViewData["CreateEditViewModelTemplate"] as Func<myproject.Web.Models.ViewModel.User.EditViewModel, HelperResult>;
}
@Html.ValidationSummary(true, "Please correct the errors and try again.")
@using (Html.BeginForm()) {
@Html.HiddenFor(model => model.UserId)
@lst(Model)
<fieldset>
<input type="submit" class="right-button" value="Back to Profile List" style="margin: 5px 0 5px 0" , tabindex="7"/>
<input type="submit" class="right-button" value="Update Profile" name="confirmButton" , tabindex="6"/>
</fieldset>
}
using System.IO;
using System.Web;
using System.Web.Mvc;
namespace myproject.Web.Core.Helpers
{
public abstract class ViewStartPageWithHelpers : ViewStartPage
{
public static void WriteLiteralTo(TextWriter writer, object content)
{
writer.Write(content);
}
public static void WriteTo(TextWriter writer, object content)
{
writer.Write(HttpUtility.HtmlEncode(content));
}
}
}
*的 // _ ViewStart.cshtml *
@using myproject.Web.Models.ViewModel.User;
@using myproject.Web.Core.Helpers;
@{
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@inherits ViewStartPageWithHelpers
@{
Func<CreateViewModel, HelperResult> h =
@<fieldset>
<legend>Contact Information</legend>
<div>
@{<table class="form-spacing">
<tr>
<td class="cell-one">* @Html.Label(item.FirstName) :</td>
<td class="cell-two">@Html.TextBox(item.FirstName, new { @class = "big-field", tabindex = "1" })</td>
<td class="cell-three" >@Html.ValidationMessage(item.FirstName)</td>
</tr>
</table>};
</div>
</fieldset>;
ViewContext.Controller.ViewData["CreateEditViewModelTemplate"]=h;
}
答案 0 :(得分:1)
如果您指的是输入元素中的奇怪值,那是因为您在事故中使用了错误的Html.TextBox重载。试试
Html.TextBox(item.FirstName, item.FirstName, new {@class = "big-field", tabindex = "1" })
或者在您选择的重载中使用强类型。