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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -