DropDownListFor助手何时改变的值id

DropDownListFor助手何时改变的值id

本文介绍了如何在asp.net mvc的2.0使用Html.DropDownListFor助手何时改变的值id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了这样的一个局部视图

I have a partial view that has something like this

 <%= Html.DropDownListFor(m => m.SelectedProductName, Model.ProductList, "Select a Product") %>

现在,您可以创建一个新的产品和编辑现有的产品。无论编辑和创建使用相同的形式。在创建上载了在主页上。编辑弹出一个jQuery UI的模式对话框,并呈现一个新的局部视图。

Now you can create a new product and edit an existing product. Both editing and creating use the same form. The create is on the main page on load up. Edit pops up in a jQuery UI model dialog and renders a new partial view.

至于象页面而言我有2下拉框具有相同的ID,它是不好的,因为它们应该是唯一的。那么,如何改变ID?所以当编辑负载,它可能是editSelectedProductName一个ID?

So as far as the page is concerned I have 2 dropdown boxes with the same "id" which is bad since they should be unique. So how do I change the id? So when the edit loads it might have a id of "editSelectedProductName"?

我试图做到这一点,在视图模型

I tried to do this in the view model

public string SelectedProductName{ get; set; }

ViewModelConstructor()
{
  SelectedProductName = "EditSelectedProductName";
}

但似乎并不在意,保持使用SelectedProductName作为产品名称

But it seems to not care and keeps using "SelectedProductName" as the product name

推荐答案

我找不到此刻的文档,但有一个重载DropDownListFor将接受属性的对象类型集合(HtmlAttributes是参数名。)

I can't find the documentation at the moment, but there is an overload for DropDownListFor that will accept an object-typed collection of attributes (HtmlAttributes is the parameter name.)

这将是这个样子:

Html.DropDownListFor(model=>model.SomeProperty, new {@id="UniqueID1234"});

您可以使用智能感知,发现包括HtmlAttributes过载。

You can use Intellisense to find the overload that includes HtmlAttributes.

这篇关于如何在asp.net mvc的2.0使用Html.DropDownListFor助手何时改变的值id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 15:12