问题描述
我正在将asp.net mvc用于购物用的非常基本的Websitre。 无论如何,我对这个标题有误
没有为此对象定义无参数构造函数。
这是我的模特:
public class BookGenre
{
public BookGenre()
{
}
[Key]
public int GenreID { get; set; }
[Display(Name = "Genre Title")]
[Required(ErrorMessage = "Please enter your {0}")]
public string GenreTitle { get; set; }
public virtual List<Book> Book { get; set; }
}
所以问题是我的模型“具有无参数的构造函数”
其他信息>>
这是我使用模型的地方:
public class PageController : Controller
{
private BooksContext db = new BooksContext();
private IBookGenreRepository bookGenreRepository;
public PageController(BooksContext context)
{
bookGenreRepository = new BookGenreRepository(db);
}
public ActionResult HeaderGenres()
{
return PartialView(bookGenreRepository.GetAllGenres());
}
}
这是“ BookGenreRepository”,其中实现了“ GetAllGenres”。
public class BookGenreRepository : IBookGenreRepository
{
BooksContext db;
public BookGenreRepository(BooksContext context)
{
db = context;
}
public IEnumerable<BookGenre> GetAllGenres()
{
return db.BookGenres;
}
public BookGenre GetGenreByID(int genreId)
{
return db.BookGenres.Find(genreId);
}
public IEnumerable<BookGenre> GetGenresByFilter(string filterBy)
{
return db.BookGenres.Where(g => g.GenreTitle.Contains(filterBy));
}
public bool AddGenre(BookGenre bookGenre)
{
try
{
db.BookGenres.Add(bookGenre);
return true;
}
catch
{
return false;
}
}
public bool EditGenre(BookGenre bookGenre)
{
try
{
db.Entry(bookGenre).State = EntityState.Modified;
return true;
}
catch
{
return false;
}
}
public bool DeleteGenre(BookGenre bookGenre)
{
try
{
db.Entry(bookGenre).State = EntityState.Deleted;
return true;
}
catch
{
return false;
}
}
public bool DeleteGenreByID(int genreId)
{
var genre = GetGenreByID(genreId);
try
{
DeleteGenre(genre);
return true;
}
catch
{
return false;
}
}
public void Save()
{
db.SaveChanges();
}
public void Dispose()
{
db.Dispose();
}
}
错误图片: this is Error picture
请有人帮助我
如果您需要有关我的代码的更多信息,请告诉我编辑问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)