ASP.NET: How to make a checkbox always unchecked even post-submit -


just started learning how develop asp.net application, puzzled on how make checkbox unchecked after form submit user tick checkbox. checkbox acknowledgment user agrees terms , conditions ... , when form submit return errors want display error message on screen , keep checkbox unchecked regardless ticked or not.

in view have following:

<%: html.checkboxfor(m => m.useragreement) %> 

and have tried both following in controller , none of them works:

viewdata["useragreement"] = false;  return view(new mymodel { useragreement = false}); 

anyone can on how achieve need? thank you.

this bothered me long time well, explicity setting values in model false did not solve problem. found was checking value in modelstate collection.

this not cleanest solution worked me:

private actionresult displayview(string viewname, mymodelclass model) {     model.agreeterms = false;     modelstate.remove("agreeterms");      return view(viewname, model); } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -