首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ViewUserControl中的ASP.NET MVC DropDownList

ViewUserControl中的ASP.NET MVC DropDownList
EN

Stack Overflow用户
提问于 2011-12-16 04:45:39
回答 1查看 191关注 0票数 0

我是MVC的新手,并被这个问题所困扰,我有一个带有小联系人表单的ViewUserControl,我已经为这个ContactForm创建了一个模式。

代码语言:javascript
复制
    [Required(ErrorMessage = "Type your Name"), DataType(DataType.Text)]
    [DisplayName("Name")]
    public string NameProperty { get; set; }

    [Required(ErrorMessage = "Type your Mobile"), DataType(DataType.Text)]
    [DisplayName("Mobile")]
    public string MobileProperty { get; set; }

    [Required(ErrorMessage = "Type your City"), DataType(DataType.Text)]
    [DisplayName("City")]
    public string CityProperty { get; set; }

    [Required(ErrorMessage = "Select Product"), DataType(DataType.Text)]
    [DisplayName("Product")]
    public IEnumerable<SelectListItem> ProductProperty { get; set; }

    [Required(ErrorMessage = "Type your Message"), DataType(DataType.MultilineText)]
    [DisplayName("Message")]
    public string MessageProduct { get; set; }

    public static IEnumerable<SelectListItem> ProductList()
    {
        List<SelectListItem> items = new List<SelectListItem>();
        items.Add(new SelectListItem { Text = "Printed Fabrics", Value = "1" });
        items.Add(new SelectListItem { Text = "Silk  Fabrics", Value = "2" });
        items.Add(new SelectListItem { Text = "Printed Silk Fabrics", Value = "3" });
        return items;
    }

ViewUserControl内幕

代码语言:javascript
复制
 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<govindHari.Models.ContactForm>" %>

现在如何在内部调用它

代码语言:javascript
复制
    <%= Html.LabelFor(m => m.CityProperty) %>
    <%= Html.TextBoxFor(m => m.CityProperty, new { @class = "textBox" })%>

    <%= Html.LabelFor(m => m.MobileProperty) %>
    <%= Html.TextBoxFor(m => m.MobileProperty, new { @class = "textBox" })%>

    <%= Html.LabelFor(m => m.ProductProperty) %>
    <%= Html.DropDownListFor(m => m.ProductProperty)%>

问题是它对我不起作用,即使我从HomeController从索引页面发送它

请帮助问候

EN

回答 1

Stack Overflow用户

发布于 2011-12-16 04:50:46

它在简单的改变后就开始工作了

m.ProductProperty, (IEnumerable) Model.ProductProperty)%>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8526352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档