我知道这个问题被问过这么多次.我已阅读并实施了所有解决方案但未获得成功.当我使用EF从数据库检索数据并在View上使用此模型后与模型绑定时,我收到此错误.
我的控制器代码是
using System.Linq;
using System.Web.Mvc;
using JsonRenderingMvcApplication.Models;
namespace JsonRenderingMvcApplication.Controllers
{
public class PublisherController : Controller
{
public ActionResult Index()
{
PublisherModel model = new PublisherModel();
using (DAL.DevelopmentEntities context = new DAL.DevelopmentEntities())
{
model.PublisherList = context.Publishers.Select(x =>
new SelectListItem()
{
Text = x.Name,
Value = x.Id.ToString()
}); ;
}
return View(model);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的查看代码是
@model JsonRenderingMvcApplication.Models.PublisherModel
@{
ViewBag.Title = "Index";
}
<div>
@Html.DisplayFor(model=>model.Id)
@Html.DropDownListFor(model => model.Id, Model.PublisherList);
</div>
<div id="booksDiv">
</div>
Run Code Online (Sandbox Code Playgroud)
我的型号代码是
using System.Collections.Generic;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
namespace …Run Code Online (Sandbox Code Playgroud) 我收到错误消息“没有为此对象定义无参数构造函数”。在MVC 5应用程序中。

控制器是:
public class HomeController : Controller
{
private IUserService userService;
public HomeController(IUserService userService)
{
this.userService = userService;
}
[HttpGet]
public ActionResult Index()
{
var user = userService.GetUser();
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
Ninject WebCOmmon CS类是:
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(QuestionWave.Web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(QuestionWave.Web.App_Start.NinjectWebCommon), "Stop")]
namespace QuestionWave.Web.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using QuestionWave.Data;
using QuestionWave.Service;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary> …Run Code Online (Sandbox Code Playgroud)