Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试绑定网格时获取泛型错误_C#_Asp.net Mvc_Asp.net Mvc 4_Kendo Ui_Kendo Grid - Fatal编程技术网

C# 尝试绑定网格时获取泛型错误

C# 尝试绑定网格时获取泛型错误,c#,asp.net-mvc,asp.net-mvc-4,kendo-ui,kendo-grid,C#,Asp.net Mvc,Asp.net Mvc 4,Kendo Ui,Kendo Grid,我试图将网格(剑道UI)与用户在文本框中输入的值绑定,但当我启动程序时,会出现如下错误 异常详细信息:System.InvalidOperationException:传递到字典的模型项的类型为“System.Collections.Generic.List`1[KendopratapSampleVCApp.Models.EmployeeDetails]”,但此字典需要类型为“KendopratapSampleVCApp.Models.ParentViewModel”的模型项 当用户在文本框中输

我试图将网格(剑道UI)与用户在
文本框中输入的值绑定,但当我启动程序时,会出现如下错误

异常详细信息:System.InvalidOperationException:传递到字典的模型项的类型为“System.Collections.Generic.List`1[KendopratapSampleVCApp.Models.EmployeeDetails]”,但此字典需要类型为“KendopratapSampleVCApp.Models.ParentViewModel”的模型项

当用户在
文本框中输入值,然后按下提交按钮时,输入的值需要显示在网格中

这是我的模型

namespace KendoPratapSampleMVCApp.Models
{
    public class TextBoxGrid
    {
        public string EnteredValue { get; set; }
        public List<EmployeeDetails> employees;
    }   
    public class ParentViewModel
    {
        public EmployeeDetails EmployeeDetails { get; set; }
        public TextBoxGrid TextBoxGrid { get; set; }
    }
    public class EmployeeDetails
    {
        public string EmployeeId { get; set; }
        public string ManagerId { get; set; }
    }
}

当我提交按钮时,它没有显示网格中的值,而是显示空网格…

错误,因为您视图的模型是ParentViewModel,但您使用

return view(GetEmployee);
IEnumerable,因此不是视图模型的对应对象。 我建议你按以下步骤做

 public ActionResult Index( TextBoxGrid model)
    {
        var viewModel = new ParentViewModel
        {
            TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList()}
            //but first change TextBoxGrid Property from emplyees to employees{get;set;}, second from  return empdtls; to  return empdtls.AsEnumarable();
        }

        return View(viewModel);
    }
    [HttpPost]
    public ActionResult PostValues(TextBoxGrid model)
    {
        TempData["enteringValue"] = model.EnteredValue;
        return View("Index",model);                
    }
您必须创建PostValues视图,或者将PostValues更改为Index,如果它为您提供了dublicat,请按以下方式更改代码

 public ActionResult Index( TextBoxGrid model)
    {
        var viewModel = new ParentViewModel
        {
            TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList()}
            //but first change TextBoxGrid Property from emplyees to employees{get;set;}, second from  return empdtls; to  return empdtls.AsEnumarable();
        }

        return View(viewModel);
    }
    [HttpPost]
    public ActionResult PostValues(TextBoxGrid model)
    {
        TempData["enteringValue"] = model.EnteredValue;
        return View("Index",model);                
    }

我更新我的答案。但这取决于您必须如何修改的逻辑,所以我只能说,您提供视图的对象必须与视图模型对应(如果您的操作是ActionResult或ViewResult等),我需要将GetEmployee()之类的方法返回到视图进行绑定。。但是如果我写的是这样的话,我该如何回报…非常感谢。。。。百分之五十已完成当我在文本框中输入值并按下“提交”按钮时,对此还有一个疑问它给出了此错误
视图“PostValues”或其主视图未找到或没有视图引擎支持搜索的位置
请告诉我如何更正此错误..pls欢迎您,我再次更改我的答案。如果对你有效,你能将答案标记为已接受吗很抱歉,我收到此错误,无法找到资源。(http 404)我是否需要从postvalues…方法调用getemployee
    [HttpPost]
    public ActionResult PostValues(TextBoxGrid model)
    {
        TempData["enteringValue"] = model.EnteredValue;
        return View("Index",model);                
    }