Posts

Showing posts with the label Razor

Checkbox Disabled Attribute In ASP.NET MVC

Answer : It is not easy to achieve this with an if condition inside the helper method because all the below markups will render a disabled chechbox. <input type="checkbox" disabled> <input type="checkbox" disabled="disabled"> <input type="checkbox" disabled="false"> <input type="checkbox" disabled="no"> <input type="checkbox" disabled="enabled"> This should work in the razor. Simple If condition and rendering what you want. @if(item.Selected) { @Html.CheckBoxFor(modelItem => item.Selected) } else { @Html.CheckBoxFor(modelItem => item.Selected, new { @disabled = "disabled"}) } You may consider writing a custom html helper which renders the proper markup for this. This won't work because <input disabled="anything" /> will result in a disabled control. You need to only have a @disabled property when it should be d...

Call Custom Confirm Dialog In Ajax.Beginform In MVC3

Answer : I came across this to customize AjaxOptions Confirm text with a value that has not been created yet when Ajax.Beginform is rendered . For example: Confirm="Are you sure you want to create Customer Id" + someValue + "?" Finally a found a solution: The approach is regarding a change in submit button behavior with JQuery to pull the value, run my own Confirm dialog and submit the Ajax form if user confirm. The steps: 1- Remove Confirm from AjaxOptions and avoid set button's type="submit", could be type="button" <div> @using (Ajax.BeginForm("Function", "Controller", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "theForm", InsertionMode = InsertionMode.Replace, LoadingElementId = "iconGif", OnBegin = "OnBegin", OnFailure = "OnFailure", OnSuccess =...