Using MVC.. when user hit's Create button and a specific field is null or white space, then display dialog box to confirm. If field has value, do not display dialog box and go straight to HttpPost Controller Method..
Here is what I have so far:
CSHTML:
<div class="form-group">
@Html.LabelFor(model => model.ATime, "ATime:", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ATime, new { htmlAttributes = new { id = "AValue", @class = "form-control a-textbox", @placeholder = "xxxx.x" } })
@Html.ValidationMessageFor(model => model.ATime, "", new { @class = "text-danger" })
</div>
</div>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.
</p>
</div>
<input type="submit" value="Create" class="btn btn-primary btnSubmitDS" />
JavaScript:
$(document).ready(function () {
$(".btnSubmitDS").on("click", function (e) {
var aValue = $("#AValue").val();
alert(aValue);
if (aValue == null || aValue.length() == 0) {
$(function () {
$('#dialog').dialog();
});
}
});
});
CSS:
#dialog{
display:none;
}
Now, the correct value is being alerted to the user when the button is clicked but throws an error at the if statement in the JS saying:
Function Expected
I have tried to recreate this in a JSFiddle and the correct value is being alerted, but the dialog box is not appearing there either, and I did include the jQuery library.
Any help is appreciated.
if (aValue == null || aValue.length === 0) { $('#dialog').dialog(); }. in the click handler.lengthis property not method. Also,$(function () {is short form ofready()and not required in the handler.