asp.net mvc 3 - Show error message with alert box -
i show error message alert box in asp.net mvc3 razor. used dataanootation model. please see below.
<required(errormessage:="name required")> _ public name string
in client side.
@html.textboxfor(function(model) model.content) @html.validationmessagefor(function(model) model.content, "please type name") @html.validationsummary()
but error message show label beside of textbox. want show alert box error message. all.
<script type="text/javascript"> @if (!viewcontext.viewdata.modelstate.isvalid) { var sb = new stringbuilder(); foreach (var modelstate in viewcontext.viewdata.modelstate.values) { foreach (var error in modelstate.errors) { sb.append(error.errormessage); } } @:alert('@sb.tostring()'); } </script>
Comments
Post a Comment