不mvc.net验证支持的ValidationGroup概念 [英] does mvc.net validation support the concept of ValidationGroup

查看:110
本文介绍了不mvc.net验证支持的ValidationGroup概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net背景的,我真的AP preciated的ValidationGroup添加验证的网页时的概念。我一直在寻找mvc.net内的相应的概念,并没有多少运气。

Coming from the asp.net background, I really appreciated the concept of 'validationGroup' when adding validation to a page. I've been searching for a corresponding concept within mvc.net and haven't had much luck.

这是概念mvc.net可用?如果不是这样,我有什么办法?

Is this concept available in mvc.net? If not, what alternatives do I have?

推荐答案

不幸的是没有,它不来这样的事情。

Unfortunately no, it doesn't come with anything like that.

我的博客上讲述一个解决方法凌晨一会儿回来。

I blogged about a workaround a wee while back.

<一个href=\"http://blog.pagedesigners.co.nz/post/1095179251/asp-net-mvc-validation-summary-with-2-forms-1-view\">ASP.NET MVC - 验证摘要与2表格及放大器; 1查看

博客文章的JIST:

namespace System.Web.Mvc
{
    public static class HtmlExtensions
    {
        public static string ActionValidationSummary(this HtmlHelper html, string action)
        {
            string currentAction = html.ViewContext.RouteData.Values["action"].ToString();

            if (currentAction.ToLower() == action.ToLower())
                return html.ValidationSummary();

            return string.Empty;
        }
    }
}

<h2>Register</h2>

<%= Html.ActionValidationSummary("Register") %>

<form method="post" id="register-form" action="<%= Html.AttributeEncode(Url.Action("Register")) %>">

    ... blah ...

</form>


<h2>User Login</h2>

<%= Html.ActionValidationSummary("LogIn") %>

<form method="post" id="login-form" action="<%= Html.AttributeEncode(Url.Action("LogIn")) %>">

    ... blah ...

</form>

HTHS,结果
查尔斯

HTHs,
Charles

这篇关于不mvc.net验证支持的ValidationGroup概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆