2017年8月31日 星期四

How to get value from GetUnobtrusiveValidationAttributes in second time

From Microsoft, by design "On the first call, a collection of attributes is returned. Further calls (on the same field) return an empty collection."


Scenario :

When you have a survey form with multiple question, and options using radio button. Then you will face the problem, the validation message only the first question will be shown.

The reason caused by Microsoft design,

Here is the solution, to set the particular property name after you call the GetUnobtrusiveValidationAttributes function.


htmlHelper.ViewContext.FormContext.RenderedField(htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(optionExpText), false);



Reference : https://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.getunobtrusivevalidationattributes(v=vs.118).aspx

沒有留言:

張貼留言