相关疑难解决方法(0)

使用带有IEnumerable <T>的Html.EditorFor

我有一个自定义类:

public class Person
{
    public String Name { get; set; }
    public Int32 Age { get; set; }
    public List<String> FavoriteFoods { get; set; }

    public Person()
    {
        this.FavoriteFoods = new List<String>();
        this.FavoriteFoods.Add("Jambalya");
    }
}
Run Code Online (Sandbox Code Playgroud)

我把这个类传递给我的强类型视图:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcLearner.Models.Person>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 Create
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Create</h2>

    <% using (Html.BeginForm()) { %>
        <%= Html.LabelFor(person => person.Name) %><br />
        <%= Html.EditorFor(person => person.Name) %><br />
        <%= Html.LabelFor(person => person.Age) %><br />
        <%= Html.EditorFor(person …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-2

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-2 ×1