English 中文(简体)
About Asp.Net MVC Helper Html. 隐蔽
原标题:About Asp.Net MVC Helper Html.Hidden

我有以下模式:

Public Class BaseViewModel

Public Property Id as integer
Public Property Title As String

<DisplayName("Creation Date"), Required(), ScaffoldColumn(False)>
Public Property DateCreation As String
<DisplayName("Creation User"), Required(), ScaffoldColumn(False)>
Public Property UserCreation As String
<DisplayName("Modification Date"), ScaffoldColumn(False)>
Public Property DateModification As String
<DisplayName("Modification User"), ScaffoldColumn(False)>
Public Property UserModification As String

End Class

I ve产生了一个部分观点,称为“基地”号,其次为“超文本”

<div id="Detail-Item" class="hidden">
@Using Html.BeginForm("Save", "Agency", Nothing, FormMethod.Post, New With {.id = "Detail-form"})
@<fieldset>
    <legend>Agency</legend>
    @Html.ValidationSummary()
    <div class="editor-label"> 
        @Html.LabelFor(Function(model) model.Id):
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(Function(model) model.Id, New With {.class = "textbox-id input-key textbox-inactive", .data_field = "Id", .readonly = "readonly"})    
        @Html.ValidationMessageFor(Function(model) model.Id, "*")
    </div>
    <div class="editor-label">
        @Html.LabelFor(Function(model) model.Title):
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(Function(model) model.Title, New With {.class = "textbox-name input-text focus", .data_field = "Title"})
        @Html.ValidationMessageFor(Function(model) model.Title, "*")
    </div>

    <div class="hidden">
        @Html.Hidden("UserCreation", String.Empty, New With {.class = "input-audituser", .data_field = "UserCreation"})
        @Html.Hidden("UserModification", String.Empty, New With {.class = "input-audituser", .data_field = "UserModification"})
        @Html.Hidden("DateCreation", String.Empty, New With {.class = "input-auditdate", .data_field = "DateCreation"})
        @Html.Hidden("DateModification", String.Empty, New With {.class = "input-auditdate", .data_field = "DateModification"})
    </div>
</fieldset>
End Using
</div>

用@html来表达这一看法。 EditForModel。 我的问题是,甚至使用Html的Im。 用于这些领域工作的Html生成的“需要”数据验证属性。

如果能避免这种情况?

最佳回答

根据你提供的模式,即预期行为。 该模型指定了两种所需的特性,因此,隐藏的田地将添加不侵扰性的验证特性。

问题回答

Hidden does not mean that it will not be validated. Why don t you just set a proper date/time in your partial view, instead of initializing those hidden fields with an empty string. Something like DateTime.Now should work.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

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. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签