如何在ASP MVC 4剃须刀中自动构建表单

时间:2014-04-14 07:45:26

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

我正在ASP MVC4中创建一个网站,razor视图。我有一个表单,使用类将一些数据输入我的数据库(使用实体框架)。

目前,我必须为我在类中添加的每个属性创建一个新输入,但我想要一个循环遍历该类并自动添加输入的autobuilder。我怎么能这样做?

这是我的班级:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LSMDB.Models
{
    public class Movie
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Poster { get; set; }
        public string Director { get; set; }
        public int Budget { get; set; }
        public string Language { get; set; }
        public int Duration { get; set; }
        public int Boxoffice { get; set; }
        public string Description { get; set; }
    }
}

提前致谢。

- 约根

1 个答案:

答案 0 :(得分:2)

您可以使用@Html.EditorForModel()为您执行此操作。