我有一个控制器动作如下
public ActionResult OpenForm() { return View("Index"); }
我的视图如下[Index.cshtml]
@model BusinessProcess.Models.HelloworldTO @using (Html.BeginForm()) { @Html.ValidationSummary(true) @Html.displayNameFor(model => model.Response_Borrower) @Html.EditorFor(model => model.Response_Borrower) }
现在问题是我对“编辑”和“视图”使用相同的视图.现在在某些情况下我希望用户只“查看”数据并将@ Html.EditorFor转换为@ Html.displayFor.有没有办法在不创建另一个视图的情况下执行此操作?
解决方法
模型:
public class HelloworldTO() { public bool Edit {get; set;} }
视图:
@model BusinessProcess.Models.HelloworldTO @if (Model.Edit) { @using (Html.BeginForm()) { @Html.ValidationSummary(true) @Html.displayNameFor(model => model.Response_Borrower) @Html.EditorFor(model => model.Response_Borrower) } } else { @Html.displayFor(model => model.Response_Borrower) }
调节器
public ActionResult OpenForm() { HelloworldTO model = new HelloworldTO (); model.Edit = /*certain circumstances*/; return View("Index",model); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。