在将员工类传递给使用Id查看时,在MVC 3中收到错误 [英] getting an error in MVC 3 while passing an employee class to view using Id

查看:69
本文介绍了在将员工类传递给使用Id查看时,在MVC 3中收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public ActionResult GetEmployeeFromEntity(int empId)

{

Employee objEmp = new Employee();

objEmp = objEmp.GetEmployeeDetailsById(empId );

返回查看(objEmp);

}



这是我的控制器



我正在跟踪错误



'/ CopleteMVCDemoTutorials'应用程序中的服务器错误。

参数字典包含'CopleteMVCDemoTutorials.Controllers.EntityEmployeeController'中方法'System.Web.Mvc.ActionResult GetEmployeeFromEntity(Int32)'的非可空类型'System.Int32'的参数'empId'的空条目。可选参数必须是引用类型,可以为空的类型,或者声明为可选参数。

参数名称:参数

public ActionResult GetEmployeeFromEntity(int empId)
{
Employee objEmp=new Employee();
objEmp= objEmp.GetEmployeeDetailsById(empId);
return View(objEmp);
}

This is my controller

and i am getiing following error

Server Error in '/CopleteMVCDemoTutorials' Application.
The parameters dictionary contains a null entry for parameter 'empId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult GetEmployeeFromEntity(Int32)' in 'CopleteMVCDemoTutorials.Controllers.EntityEmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

推荐答案

此错误意味着MVC框架无法为您的empId属性找到值,您应将其作为参数传递给GetEmployeeFromEntity操作。您是否在URL中提供了该值?
This error means that the MVC framework can't find a value for your empId property that you should pass as an argument to the GetEmployeeFromEntity action. Are you supplying that value in your URL?


这篇关于在将员工类传递给使用Id查看时,在MVC 3中收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆