MVC Scaffold Template Not Generating?

Posted by monkey9987 on ASP.net Weblogs See other posts from ASP.net Weblogs or by monkey9987
Published on Fri, 11 Feb 2011 21:30:00 GMT Indexed on 2011/02/11 23:26 UTC
Read the original article Hit count: 290

Filed under:
|

Been working on an MVC project and my templates were not generating. I first created my Model inside my "Models" folder, then did a quick compile. Next I went to the Views folder to get it created, right click and say "Add View" then I clicked the checkbox to create an edit page. What happened was the template would never seem to pull in my Model, it would just have the default header items, but the entire model was missing.

Scaffold Example

 My model was defined as follows:

public class LogOnModel

{

[Required]
[
Display(Name = "User name")]
public string UserName;

[Required]
[
DataType(DataType.Password)]
[
Display(Name = "Password")]
public string Password;[Display(Name = "Remember me?")]
public bool RememberMe;

}

See anything wrong with that? I couldn't figure out why each time I created my View and selected the option to create the "Edit" scaffold automatically, it would come up blank.

Turns out I'm missing my get / set methods on the Model class items.

Here's my code with the correct setup:

public class LogOnModel

{

[Required]
[
Display(Name = "User name")]
public string UserName { get; set; }

[Required]
[
DataType(DataType.Password)]
[
Display(Name = "Password")]
public string Password { get; set; }

[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }

}

 I hope that helps someone out, it's pretty simple when I look at it now, but that's always the case!

 ~ Steve

© ASP.net Weblogs or respective owner

Related posts about mvc

Related posts about ASP.NET