0

I have the following class in a class library

  public class ExpenseDTO
{
    [Key]
   public Int32 ExpenseId { get; set; }
   public Int32 ExpenseTypeId { get; set; }

    [Display(ResourceType = typeof(Resource), Name = "ExpenseDate")]
    [Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseDataRequired")]
    [DataType(DataType.Date,ErrorMessageResourceName="InvalidDateFormat"
        ,ErrorMessageResourceType=typeof(Resource))]
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
   public DateTime ExpenseDate { get; set; }

    [MaxLength(200, ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseNoteMaxLength")]
    [Display(ResourceType = typeof(Resource), Name = "ExpenseNote")]
   public  String ExpenseNote { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseAmountRequired")]
    [Display(ResourceType = typeof(Resource), Name = "ExpenseAmount")]
    public decimal ExpenseAmount { get; set; }

    public ExpenseDTO()
    {
        ExpenseNote = String.Empty;

    }

}

i also have an asp.net MVC 4 project that has a class named ExpenseEditView with the following definition

public class ExpenseEditView
{
    public ExpenseDTO Expense { get; set; }
    public IEnumerable<SelectListItem> ExpenseTypeList { get; set; }
    public ExpenseEditView(ExpenseDTO Expense, IEnumerable<SelectListItem> ExpenseTypeList)
    {
        this.Expense = Expense;
        this.ExpenseTypeList = ExpenseTypeList;
    }
}

In the create method of my controller i have the following line:

public ActionResult Create()
    {
        ExpenseEditView ExpenseEdit = new ExpenseEditView(new ExpenseDTO(), GetExpenseTypeList());
        return View(ExpenseEdit);
    }

When i tried to use Asp.net mvc Scaffolding template for "create" Action, it created an empty view without generating any code for the properties inside class ExpenseDTO?

Can any one please point me to what i am missing so that the template can be generated automatically for ExpenseEditView?

2 Answers2

2

Naming the view "Create" isn't what gets you the Create action. Instead, you have to:

  1. Check the "Create strongly-typed view" checkbox

  2. Choose a Model class. The dropdown for which Template you wanted to use becomes enabled.

  3. Change the dropdown from "Empty" (what you got) to "Create."

That will solve your problem.

Related: https://stackoverflow.com/a/16072432/176877

Community
  • 1
  • 1
Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
0

I haven't used it but here are thinks to look on

http://msdn.microsoft.com/en-us/library/dd405231(v=vs.100).aspx

How do I create my own Scaffold Template in ASP.NET MVC 3?

Code generation: Custom controller templates

Community
  • 1
  • 1
Nipun Ambastha
  • 2,553
  • 1
  • 16
  • 26