2017-07-21 26 views
0

在MVC JsonResult残疾人专用我有一个模型类是这样的: -值是不是从角功能

public class InternShip 
{ 
    [Key] 
    public int ID { get; set; } 
    public string Name { get; set; } 
    public string Descr { get; set; } 
    public int Amount { get; set; } 
    public int Duration { get; set; } 
    public DateTime CreatedDate { get; set; } 
    public DateTime ExpiryDate { get; set; } 

} 

现在我已经在我创建NG-click事件的看法: -

<a ng-click="IntrnDetail(r.ID)" style="cursor:pointer"><h5>{{r.Name}}</h5></a> 

在点击我的价值传递给它由功能handeled我的角度文件InternShip.js: -

$scope.IntrnDetail = function (InternID) { 
     window.location.href = '/Home/InternDetail/' + InternID; 
    } 

现在我的控制器(HomeController的)拥有的ActionResult(InternDetail)为: -

[HttpGet] 
    public JsonResult InternDetail(string InterID) 
    { 
     List<InternShip> Intern = new List<InternShip>(); 
     int IntID = Convert.ToInt32(InterID); 
     using (EBContext db = new EBContext()) 
     { 
      Intern = db.Interns.Where(x => x.ID == IntID).ToList(); 
     } 

     return new JsonResult{ Data= Intern, JsonRequestBehavior=JsonRequestBehavior.AllowGet}; 
    } 

但问题是,虽然值内InternShip.js的InternID但在JsonResult未来(InternDetail)InterID越来越空。我不知道为什么会发生这种情况。

请帮助!

回答

1

这里的问题是,因为默认的MVC路线的路线是一样的东西

{action}/{controller}/id(optional) 

意味着,当你通过

"Home/Index/3" 

的路线将id的值设置为3 现在你的动作结果参数不是id而是interID所以要么做

window.location.href ='/Home/InternDetail?InterID='+InternID ; 

或改变interIDID

public JsonResult InternDetail(int ID) 

,你还可以配置你的路线

+0

这做到了。谢谢你的解释。 – Deepak