Validation / Error Messages in ASP.Net MVC 2 View Unrelated to a Property -


what pattern can use display errors on mvc 2 view not related single property?

for example, when call web service process form data, web service may return error or throw exception. display user-friendly version of error, have no logical means relate error given property of model.

update:

trying use code suggested, no summary message displayed:

mypage.spark:

html.validationsummary(false, "oopps didn't work."); 

controller:

viewdata.modelstate.addmodelerror("_form", "my custom error message."); // tried this: viewdata.modelstate.addmodelerror(string.empty, "my custom error message."); return view(); 

update 2

what mean?

next each field.

instead of displaying validation errors, html.validationsummary helper method has new option display model-level errors. enables model-level errors displayed in validation summary , field-specific errors displayed next each field.

source: http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc#_toc3_14

specifically, how 1 add model level error (as opposed field-specific error) model?

update 3:

i noticed morning html.validationsummary not displaying errors @ all, not property errors. trying sort out why.

simply adding custom error modelstate object in conjunction validationsummary() extension method should trick. use "_form" key... won't conflict fields.

as far patterns go, have setup business logic layer (called via services controller) throw custom exception if expected goes wrong want display on view. custom exception contains dictionary<string, string> property has errors should add modelstate.

hths,
charles


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -