开发者

MVC Partial Views Validations

I have a question for a behaviour that I don't understand. I have added some data annotation to my PartialClass, and created a partial view for it. All works as expected if I use

 @Html.Partial("_partial", new Part开发者_开发问答ialClass())

On my View. The problem is that if I try to get the same partial view from my controller, using

    public ActionResult GetNew()
    {
        return PartialView("_partial", new PartialClass());
    }

I don't get the same results, because the HTML that is render is different. Don't have any validation tags.

Can anyone help me to understand and to get the same HTML from my PartialView in my controller?


Use unobtrusive javascript and tell jQuery that it needs to include the newly loaded form' for validation

See my posting on this at:

ASP.Net MVC: Can you use Data Annotations / Validation with an AJAX / jQuery call?

Its probably because your FormContext doesn't exist when you call it via GetNew - the attributes aren't rendered out unless there is a FormContext

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜