English 中文(简体)
采用ASP.net MVC模板生成动态名称
原标题:Dynamic name generation with ASP.net MVC template

让我说:

@Html.EditorFor(i => i.Date)

......和我有一个固定日期项目的模板。 在我的模板中,我有......

<input type="text" name="???" />

Given that the template only receives a DateTime instance, how can one have the template dynamically generate the name of the form field based on the original Model property name being assigned to the template?

Otherwise, upon post back, the model binder won t be able to match up the value from the template with the Date property assigned to it!

Cheers, Ian。

最佳回答

反过来,你也可以使用Html。 文本Box, 而不是写出输入标,而是为你处理:

@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new {@class = "date"})

离开这个名字是空洞的,将自动为你们居住。 如果你想明确写出超文本标签,我认为你可以找到名字:

<input type="text" name="@ViewData.ModelMetadata.DataTypeName" />
问题回答

暂无回答




相关问题
Using jquery to get a partial view and updating the UI

I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can ...

MVC 2 / MVC 3 / MVC 4

MVC 2 我们可以轻松地创造领域。 现在,我的问题涉及nes地区(地区内)。

Asp.Net MVC 2 - Changing the PropertyValueRequired string

Using a resx file in the App_GlobalResources directory, I ve been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn t work to translate the ...

ASP.NET MVC 3 - What features do you want to see? [closed]

I know a bunch of people that are really enjoying the improvements that ASP.NET MVC 2 made over the first release. I have just started to migrate our MVC 1 project over and so far areas has totally ...

热门标签