0

I would like to conditionally disable this button, or hide it, if Model.Promotion.PromotionID is 10. Not sure how to do it. i am attempted to find the solution but struggling with it.

Would appreciate some help thanks

 @using (Html.BeginForm("Edit", "Promotion", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    @Html.HiddenFor(model => model.Promotion.PromotionID)

    @Html.HiddenFor(model => model.Promotion.Active)


    <fieldset class="fieldset">
        <legend class="legend">Edit Promotion</legend>

        <div>

        <div class="editor-field" title="The name of the Promotion"  @((Model.Promotion.PromotionID == 209) ? "disabled" : "")>
                    @Html.EditorFor(model => model.Promotion.PromotionTitle )
                    @Html.ValidationMessageFor(model => model.Promotion.PromotionTitle)
                </div>

                </div>
cedPound
  • 367
  • 1
  • 3
  • 14
  • Disabling a DIV won't do anything. You'd need to disable the Razor call. – krillgar Dec 14 '16 at 15:46
  • @krillgar do you have an example? – cedPound Dec 14 '16 at 15:52
  • I don't use `.EditorFor`, so there are [existing questions](http://stackoverflow.com/questions/1625327/editorfor-and-html-properties), or [the documentation](https://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor(v=vs.118).aspx#M:System.Web.Mvc.Html.EditorExtensions.EditorFor``2%28System.Web.Mvc.HtmlHelper{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Object%29) that can help. – krillgar Dec 14 '16 at 15:55
  • `@if (Model.Model.Promotion.PromotionID == 209) { @Html.DisplayFor(m => m.Promotion.PromotionTitle ) controls } else { // generate html above }` –  Dec 14 '16 at 23:12
  • @StephenMuecke generate what html above can you put it in a block of code if you dont mind – cedPound Dec 15 '16 at 09:39
  • Its just your `@Html.EditorFor()` and `@Html.ValidationMessageFor()` lines of code –  Dec 15 '16 at 09:42
  • @StephenMuecke i understand your code but what im trying to do is to disable all the html if the promotion ID == 209 so if Model.Model.Promotion.Promotion ID == 209 ? disabled = "disabled) etc but this is not working – cedPound Dec 15 '16 at 09:55
  • What in the world for. Disabled controls do not submit a value so you may as well just use `DisplayFor()` (and style it to look like a disabled textbox it that is what you want. And there no point rendering a pointless `ValidationMessageFor()` if the control is disabled (and there is no such thing as a disabled div) –  Dec 15 '16 at 09:57
  • @StephenMuecke i misunderstood your concept earlier i now get the displayfor will just display the data which means that the user wont be able to edit it – cedPound Dec 15 '16 at 10:24

0 Answers0