我有Registration
控制器:傳遞到字典的模型是類型「TestApp.Models.Registration.RegistrationVm」,但這部詞典需要System.String類型的模型項目
public class RegistrationController : Controller
{
private RegistrationVmBuilder _registrationVmBuilder = new RegistrationVmBuilder();
public ActionResult Index()
{
return View(_registrationVmBuilder.BuildRegistrationVm());
}
}
和RegistrationBuilder
類:
public class RegistrationVmBuilder
{
public RegistrationVm BuildRegistrationVm()
{
RegistrationVm registrationVm = new RegistrationVm
{
Courses = GetSerializedCourseVms(),
Instructors = GetSerializedInstructors()
};
return registrationVm;
}
}
RegistrationVm
類:
public class RegistrationVm
{
public string Courses { get; set; }
public string Instructors { get; set; }
}
_Layout.cshtml:
@model string
<html ng-app="registrationModule">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="~/Scripts/jquery-2.1.4.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/registration-module.js"></script>
@RenderSection("JavascriptInHead")
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap-state.min.css" rel="stylesheet" />
<title>College Registration</title>
</head>
<body>
@RenderBody()
</body>
</html>
而且在索引視圖:
@model TestApp.Models.Registration.RegistrationVm
問題是,當我跑我得到這個錯誤的程序:
The model item passed into the dictionary is of type 'TestApp.Models.Registration.RegistrationVm', but this dictionary requires a model item of type 'System.String'.
你的哪行代碼會得到這個錯誤? – alisabzevari
@alisabzevari在註冊網址中運行應用程序後。 – user2019037
你是什麼意思的註冊網址? – alisabzevari