私のアプリケーションはMVC3ASPXC#です。次を使用してHtml.EditorForを有効/無効にしようとしています。モデル内:
public bool IsReadOnly { get; private set; }
コントローラ内:
if (MySession.Current._progress == 100)
ViewData["ReadOnly"] = true;
ビューで:
... Inherits="System.Web.Mvc.ViewPage<Models.CTAHFormEdit>" %>
<script runat="server" type="text/C#">
bool isReadOnly = false;
protected void Page_Load(object sender, EventArgs e)
{
if ((bool?)this.ViewData["ReadOnly"] == true)this.isReadOnly = true;
}
</script>
<%: Html.EditorFor(model => model.Vessel_calcification, Model.IsReadOnly)%>
これは機能しませんでした。私も試しました:
<%: Html.EditorFor(model => model.Subject_motion, new { @disable = true })%>
も動作しませんでした!
同じビューにドロップダウンリストとチェックボックスもあるため、最善の解決策は、@ disable=trueおよび@readonly=trueまたはfalseを使用し、ViewBagを使用してtrueまたはfalseを変更できるようにすることです。どんな提案でも、事前に感謝します。