ASP.NET MVC 3:生成不显眼的审定时BeginForm是布局 [英] ASP.NET MVC 3: Generate unobtrusive validation when BeginForm is on the layout

查看:119
本文介绍了ASP.NET MVC 3:生成不显眼的审定时BeginForm是布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚意识到,当我把一个表单标签我的布局页面上,围绕RenderBody部分,是不是正在生成不显眼的验证。事情是这样的:

I just realized that when I place a form tag on my layout page, surrounding the RenderBody section, the unobtrusive validation is not being generated. Something like this:

@using (Html.BeginForm())
{
    <input type="submit" value="save" />

    <div>
        @RenderBody()
    </div>
}

正如你可能已经猜到我要生成过我的内容的按钮。这是正确的不显眼的行为?

As you might have guessed I want to generate buttons over my content. Is this the correct unobtrusive's behavior?

顺便说一句,如果我在表单的特定页面内,一切就像一个魅力:数据-VAL *属性以及生成的

BTW, If I place the form inside a particular page, everything works like a charm: the data-val* attributes are well generated.

我将AP preciate宝贵的帮助。

I'll appreciate your valuable help.

问候

罗德里戈

推荐答案

感谢您的帮助,我尝试过,但我发现了一个解决方案,而不是四不像(如你所说)如你所说:D

Thanks for your help, I tried it but I found a solution not as "grotesque" (as you said) as you suggested :D

我只是把BeginForm方法我的网页里面,也是一个BeginForm方法上的布局:

I simply put a BeginForm method inside my page and also a BeginForm method on the layout:

@* On the layout page *@
@using (Html.BeginForm())
{
    <input type="submit" value="save" />

    <div>
        @RenderBody()
    </div>
}


@* On the content page *@
@using(Html.BeginForm())
{
  @* Content *@
}

所以,最后我有两个BeginForm方法:ASP.NET MVC引擎是使用一个位于页面布局上,所以数据-VAL *属性被正确地呈现在哪里,我想这样的形式刚放置提交任何布局上的按钮可以提交我的特定页面与验证渲染

so, at the end I have two BeginForm methods: ASP.NET MVC engine is using the one located on the layout page, so the data-val* attributes are being rendered correctly and the form is placed just where I wanted so any submit button on the layout can submit my particular page with the validations rendered

它的工作原理pretty以及

It works pretty well

非常感谢

问候,
罗德里戈

这篇关于ASP.NET MVC 3:生成不显眼的审定时BeginForm是布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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