简体   繁体   English

Microsoft JScript运行时错误:“ data.EmployeeDetails.EmployeeId”为null或不是对象`

[英]Microsoft JScript runtime error: 'data.EmployeeDetails.EmployeeId' is null or not an object`

HI I am stuck in getting data that i need to display in kendo UI GRID , Initially I am able to see the button and textbox and grid as well but when i enter the value in textbox and then press the button i need to show that entered values in kendo UI GRID ... 嗨,我一直在获取需要在kendo UI GRID中显示的数据,最初我也能够看到按钮,文本框和网格,但是当我在文本框中输入值然后按按钮时,我需要显示输入的内容kendo UI GRID中的值...

When I run this application in google chrome it was giving empty grid,after enters the value and then press the submit button but when I run this one in IE8 it was giving error like this at starting stage itself.... 当我在谷歌浏览器中运行此应用程序时,它给出了一个空网格,输入值后,然后按了提交按钮,但是当我在IE8中运行此应用程序时,它在开始阶段本身就给出了这样的错误。

Unhandled exception at line 238, column 37 in Function code 0x800a138f - Microsoft JScript runtime error: 'data.EmployeeDetails.EmployeeId' is null or not an object

and this is my model 这是我的模特

    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; }
    }

this is my controller 这是我的控制器

public class EnterValuesGridController : Controller
{
    private static List<EmployeeDetails> empdtls;
    public ActionResult Index( ParentViewModel model)
    {
        var viewmodel = new ParentViewModel
        {
            TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
        };
        return View(viewmodel);
    }      
    [HttpPost]
    public ActionResult PostValues(TextBoxGrid model)
    {
        TempData["enteringValue"] = model.EnteredValue;
        var viewmodel = new ParentViewModel
        {
            TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
        };
        //ParentViewModel p = new ParentViewModel();
        //TextBoxGrid t = new TextBoxGrid();
        //t.EnteredValue = "a";
        //TempData["a1"] = t.EnteredValue;
        //t.employees = GetEmployee().ToList();
        //p.TextBoxGrid = t;
        //return View("Index", p);   
        return View("Index", viewmodel);        
    }
    public  IEnumerable<EmployeeDetails> GetEmployee()
    {
        string enteredValueId =(string) TempData["enteringValue"];
        string managerId = "M" +enteredValueId;
        empdtls = new List<EmployeeDetails>();
        EmployeeDetails em1 = new EmployeeDetails();
        em1.EmployeeId = enteredValueId;
        em1.ManagerId = managerId;
        empdtls.Add(em1);
        return empdtls.AsEnumerable();
    }
    public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
    {
        return Json(GetOrders().ToDataSourceResult(request));
    }
    private IEnumerable<EmployeeDetails> GetOrders()
    {
        return GetEmployee().AsEnumerable();
    }
}

and this is my view 这是我的看法

@model KendoPratapSampleMVCApp.Models.ParentViewModel
@{
    ViewBag.Title = "Index";
}    
@using (Html.BeginForm("PostValues", "EnterValuesGrid", FormMethod.Post))
{ 
     @Html.TextBoxFor(m=>m.TextBoxGrid.EnteredValue)    
     <input type="submit" name="Submitbutton1" value="Submit1" />               
     @(Html.Kendo().Grid<KendoPratapSampleMVCApp.Models.ParentViewModel>()    
    .Name("grid")
    .Columns(columns => {
        columns.Bound(s=>s.EmployeeDetails.EmployeeId).Filterable(false).Width(100);
        columns.Bound(s => s.EmployeeDetails.ManagerId).Filterable(false).Width(100);        
    })
    .Filterable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource       
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Orders_Read", "EnterValuesGrid"))
     )
  )        
} 

I am not sure where I am doing wrong, Would you pls suggest any ideas on this one .. Many thanks...., Do i need to do any changes in UI GRID I have tried changing the post values method ...but it didnot worked for me ... 我不确定我在哪里做错了,请问您对此有何建议。。非常感谢....,我是否需要对UI GRID进行任何更改?它对我没有用...

UPDATE : changed tempData to view Bag... 更新:更改了tempData以查看Bag ...

    [HttpPost]
    public ActionResult PostValues(ParentViewModel model)
    {
        ViewBag.item = model.TextBoxGrid.EnteredValue;

        var viewmodel = new ParentViewModel
        {
            TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }

        };

        //ParentViewModel p = new ParentViewModel();
        //TextBoxGrid t = new TextBoxGrid();
        //t.EnteredValue = "a";
        //TempData["a1"] = t.EnteredValue;
        //t.employees = GetEmployee().ToList();
        //p.TextBoxGrid = t;
        //return View("Index", p);   
        return View("Index", viewmodel);        
    }

    public  IEnumerable<EmployeeDetails> GetEmployee()
    {
        string enteredValueId = (string)ViewBag.item;
        string managerId = "M" +enteredValueId;
        empdtls = new List<EmployeeDetails>();
        EmployeeDetails em1 = new EmployeeDetails();
        em1.EmployeeId = enteredValueId;
        em1.ManagerId = managerId;
        empdtls.Add(em1);
        return empdtls;
    }

Hi pratap i just update your code, 嗨,pratap,我只是更新您的代码,

Model 模型

 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 EnteredValue { get; set; }
        public string EmployeeId { get; set; }
        public string ManagerId { get; set; }
    }

View 视图

@model TwoModelInSinglePageModel.EmployeeDetails
@{
    ViewBag.Title = "Index";
}
<script src="~/Script/Jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="~/Script/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Script/kendo.all.min.js")" type="text/javascript"></script>
<script src="~/Script/kendo.web.min.js" type="text/javascript"></script>
<script src="~/Script/kendo.aspnetmvc.min.js" type="text/javascript"></script>

@using (Html.BeginForm("PostValues", "Test", FormMethod.Post))
{ 
    @Html.TextBoxFor(m => m.EnteredValue)    
    <input type="submit" name="Submitbutton1" value="Submit1" />               
    @(Html.Kendo().Grid<TwoModelInSinglePageModel.EmployeeDetails>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(s => s.EmployeeId);
        columns.Bound(s => s.ManagerId);
    })
    .Filterable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
           .Read(read => read.Action("Orders_Read", "Test"))
     )
  )        
}

Controller 调节器

private static List<EmployeeDetails> empdtls;
    public ActionResult PostValues()
    {
        return View();
    }

[HttpPost]
public ActionResult PostValues(EmployeeDetails model)
{
    ViewBag.item = model.EnteredValue;

    ParentViewModel viewmodels = new ParentViewModel
    {
        TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }

    };

    ParentViewModel viewmodel = new ParentViewModel();
    EmployeeDetails em1 = new EmployeeDetails();
    for (int i = 0; i < viewmodels.TextBoxGrid.employees.Count(); i++)
    {

        em1.EmployeeId = viewmodels.TextBoxGrid.employees[i].EmployeeId;
        em1.ManagerId = viewmodels.TextBoxGrid.employees[i].ManagerId;
        viewmodel.EmployeeDetails = em1;
    }
    Session["EM1"] = em1;
    return View("PostValues", em1);
}

public List<EmployeeDetails> GetEmployee()
{
    string enteredValueId = (string)ViewBag.item;
    string managerId = "M" + enteredValueId;
    empdtls = new List<EmployeeDetails>();
    EmployeeDetails em1 = new EmployeeDetails();
    em1.EmployeeId = enteredValueId;
    em1.ManagerId = managerId;
    if (Session["EM1"] != null)
    {
        em1 = Session["EM1"] as EmployeeDetails;

        empdtls.Add(em1);
        Session["EM1"] = null;
    }
    else
    {
        empdtls.Add(em1);
    }
    return empdtls;
}

public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request, EmployeeDetails model)
{
    return Json(GetEmployee().ToDataSourceResult(request));
}

OK, I read through your post again and you want to submit the form when click on the button actually. 好的,我再次通读了您的帖子,您实际上想在单击按钮时提交表格。 So, let's try to put the value in the session 因此,让我们尝试将值放入会话中

Session["enteringValue"] = model.EnteredValue;

And you can retrieve it using 您可以使用

string enteredValueId = (string)(Session["enteringValue"]);

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

相关问题 Microsoft JScript运行时错误:“null”为null或不是对象 - Microsoft JScript runtime error: 'null' is null or not an object Microsoft JScript 运行时错误:'Sys.Extended.UI' 是 null 或者不是 object - Microsoft JScript runtime error: 'Sys.Extended.UI' is null or not an object Microsoft JScript运行时错误:预期对象 - Microsoft JScript runtime error: Object expected jQuery“Microsoft JScript运行时错误:对象预期” - jQuery “Microsoft JScript runtime error: Object expected” Microsoft JScript运行时错误:无法获取属性&#39;removeChild&#39;的值:对象为null或未定义 - Microsoft JScript runtime error: Unable to get value of the property 'removeChild': object is null or undefined Microsoft JScript运行时错误:无法获取属性“样式”的值:对象为null或未定义 - Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined Microsoft JScript运行时错误:对象不支持此属性或方法 - Microsoft JScript runtime error: Object doesn't support this property or method Microsoft JScript运行时错误:对象不支持此属性或方法 - Microsoft JScript runtime error: Object doesn't support this property or method Microsoft JScript中的运行时错误:未定义“数组” - Runtime Error in Microsoft JScript: 'Array' is not defined BHO插件(Microsoft JScript运行时错误) - BHO Plugin (Microsoft JScript runtime error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM