繁体   English   中英

传递视图 model 以在 ASP.NET MVC 中查看时出错

[英]Error while passing view model to view in ASP.NET MVC

我的观点是这样的:

@model SystemBase.Domain.ViewModel.SelfDeclarationReportViewModel
@{
    ViewBag.Title = "testi";
    Layout = "~/Areas/AdminAgency/Views/Shared/_Layout.cshtml";
}

我想使用以下代码将声明的视图 model class 的一些数据传递给我的视图:

public ActionResult Index(Guid companyID, Guid periodID, EvaluationType evaluationType)
{
    try
    {
        var form = _FormsService.GetMandatory(companyID, 
            periodID, EvaluationType.Mandatory);
        var userForm = _UserFormService.GetMandatoryWithSelfDeclarationScores(
            User.UserID().Value, companyID, periodID);

        if (userForm == null)
        {
            userForm = _UserFormService.CreateMandatoryUserForm(form, 
                companyID, User.UserID().Value);
        }

        var m = new SelfDeclarationReportViewModel();
        m.Form = form;
        m.Userform = userForm;

        return View(m);
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

在调试模式下,一切似乎都正常,断点在视图和 controller 中都有效,但是 output 是此消息的错误

传入字典的 model 项的类型为“SystemBase.Domain.ViewModel.SelfDeclarationReportViewModel”,但该字典需要“SystemBase.Domain.ViewModel.OrganizationViewModel”类型的 model 项。

您忘记了属于索引视图的返回一个返回视图

索引.cshtml

            try
            {
                var studentViewModel = new StudentViewModel();
                
                return View(studentViewModel);
            }
            catch
            {

            }
            return View();        //here you need to return something other wise you get an error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM