English 中文(简体)
页: 1
原标题:asp .net MVC 2.0 Validation

I’m trying to do some validation in asp .net MVC 2.0 for my application. I want to have some nice client side validation. Validation should be done most time on model side with DataAnnotations with custom attributes( like CompareTo, StringLenght, MinPasswordLenght (from Membership.MinimumumpassworkdLenght value). For that purpose I tried to use xval with jquery.validation. Some specific thing is that most of forms will be working with ajax and most problems are when I want to validate form with ajax.

http://www.sendspace.com/file/m9gl54“rel=“nofollow noreferer” http://www.sendspace.com/file/m9gl54。 。

我采取两种控制形式。 ValidFormControl1.ascx, ValidFormControl2.ascx

<% using (Ajax.BeginForm("CreateValidForm", "Test", new AjaxOptions { HttpMethod = "Post" }))    {%> <div id="validationSummary1">
    <%= Html.ValidationSummary(true)%> </div> <fieldset>
    <legend>Fields</legend>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Name)%>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.Name)%>
        <%= Html.ValidationMessageFor(model => model.Name)%>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Email)%>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.Email)%>
        <%= Html.ValidationMessageFor(model => model.Email)%>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Password)%>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.Password)%>
        <%= Html.ValidationMessageFor(model => model.Password)%>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.ConfirmPassword)%>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.ConfirmPassword)%>
        <%= Html.ValidationMessageFor(model => model.ConfirmPassword)%>
    </div>
    <p>
        <input type="submit" value="Create" />
    </p> </fieldset> <% } %> <%= Html.ClientSideValidation<ValidModel>()
    .UseValidationSummary("validationSummary1", "Please fix the following problems:") %>

两种情况相同,只是验证摘要(效力验证摘要1,验证摘要2)。 两种控制均在一页上:

Form2
    <%Html.RenderPartial("~/Views/Test/ValidFormControl2.ascx", null); %>
Form1
   
<%Html.RenderPartial("~/Views/Test/ValidFormControl.ascx", null); %>

<>地平>

First problem, when we have two controls with same type to validate it don’t work becosue html elements are rendered by field name ( so we have two element with same name “Password” ). Only first form will be validated by client side. The worst thing is that even if we have different types and their fields name is same validation won’t work too ( this thing is what I need to repair it will be stupid to name some unique properites for validation ).

www.un.org/Depts/DGACM/index_spanish.htm 是否有解决办法?

<><>><><>Custom Substances accreditation>>

接下来的习俗属实验证(所有这些错误都是在我使用Ajax进行正常形式的验证工作时没有问题):

比较 简而言之,在记账模型的湿度模板中做了比较(对两个财产的分类称呼将作一比较),该数字在页上没有显示。 为了做到这一点,我设立了自己的《规则》提供人,比较《规则》和我的《标准》。 或许更容易做到这一点?

我拿着最低和最高值的强力,没有描述我是如何做的,但是否很容易去做?

http://www.ohchr.org。

当我对网页上的所有摘要验证信息有两种控制时,甚至Xval生成的文字都说,内容识别对摘要而言是不同的。 谁知道如何修补?

http://www.ohchr.org。

在Html的地方,是否可选择转电。 婚姻 For (model => model.ConfirmPasword). 对我来说,它没有显示。 我想有摘要和近距离实地信息,不仅是红边界。 任何人都知道如何这样做?

<>Ajax>

Anyone know how to do easy without massive code in javascript to do submit via javascript. This will be used to change input submit to href element (a). Both look same the difference is only validation summaryID

问题回答

首先,我不知道,为什么你想有两个相同的领域,一个形式。 每种形式都应有自己的模式,并使用一种模式作为有效手段。

namespace Sample.Models { [metatype(typeof(PersonaValidation))] public partial class Person { } public class PersonValidation { [Required(ErrorMessage = "First name Required")] [StringLength(20, ErrorMessage = "First name must be 20 or less characters in length")] [DisplayName("First Name")] public string Firstname { get; set; }

    [Required(ErrorMessage = "Last name Required")]
    [StringLength(20, ErrorMessage = "Last name must be 20 or less characters in length")]
    [DisplayName("Last Name")]
    public string Lastname { get; set; }

} }

在您的表格中,在标记前添加以下文字档案:

<h2>Validation Sample</h2>

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>   
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>   
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>   
<% Html.EnableClientValidation(); %>

<% using (Html.BeginForm()) {%>
    <%= Html.ValidationSummary(true) %>
      <fieldset>

        <div class="editor-label">
            <%= Html.LabelFor(model => model.Firstname) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(model => model.Firstname) %>
            <%= Html.ValidationMessageFor(model => model.Firstname) %>
        </div>

        <div class="editor-label">
            <%= Html.LabelFor(model => model.Lastname) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(model => model.Lastname) %>
            <%= Html.ValidationMessageFor(model => model.Lastname) %>
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>

<% } %>

这将每次工作。 傲慢电文将张贴到无效领域。

关于x子,你只能把 but子放在你的形式上,然后通过 j子点击。 这也将导致你的形式被张贴。

你还可以呼吁控制者采取行动(联系点击),并在此附上你表格的必要数据。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签