【问题标题】:Form posting issue in MVCMVC 中的表单发布问题
【发布时间】:2017-05-29 07:15:30
【问题描述】:

模型结构

UserModel.cs

public class PatientViewModel
{
    public int? inPatientId { get; set; }
    public string stFirstName { get; set; }
}

TaskModel.cs

public class TaskViewModel: PatientViewModel
{
    public int? inTaskId { get; set; }
    public int? inPatientid { get; set; }
    public string stName {get;set;}
}

UserTask.cshtml

@model Web.Areas.Tasks.Models.TaskViewModel

用户控制器.cs

[HttpPost]
public ActionResult saveTask(TaskViewModel loTaskViewModel)
{
    return View("~/Areas/Tasks/Views/Tasks/UserTask.cshtml", loTaskViewModel);
}

在将另一个模型类继承到主模型类时,无法发布此表单,出现错误500 (Internal Server Error)。因此,当我从 TaskModel.cs 类文件中删除这段代码 : PatientViewModel 时,表单已成功发布。

但我想将该模型继承到主模型并发布表单。

提前致谢。

【问题讨论】:

    标签: asp.net-mvc model http-post


    【解决方案1】:

    找到解决方案。问题出在模型属性声明 'inPatientId' & 'inPatientid' 中,这在模型类中是相同的,但在大小写方面不同。

    改成

    UserModel.cs

    public class PatientViewModel
    {
        public int? inPatientId { get; set; }
        public string stFirstName { get; set; }
    }
    

    TaskModel.cs

    public class TaskViewModel: PatientViewModel
    {
        public int? inTaskId { get; set; }
        public int? inPatientid { get; set; }
        public string stName {get;set;}
    }
    

    UserModel.cs

    public class PatientViewModel
    {
        public int? inPatientId { get; set; }
        public string stFirstName { get; set; }
    }
    

    TaskModel.cs

    public class TaskViewModel: PatientViewModel
    {
        public int? inTaskId { get; set; }
        public int? inTaskPatientId { get; set; }
        public string stName {get;set;}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2023-04-09
      相关资源
      最近更新 更多