0

I've a model class like this:-

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

}

Now I've a view in which I've created ng-click event:-

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

On Click my value passes to my angular file InternShip.js where it is handeled by function:-

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

Now My Controller (HomeController) has ActionResult(InternDetail) as:-

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

But the problem is although value is coming inside InternID of InternShip.js but in JsonResult (InternDetail) InterID is getting null. I don't know why is that happening.

Please HELP!!

1 Answer 1

1

The issue here is with your route since default mvc route is something like

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

means that when you pass

"Home/Index/3" 

the route will set the value of id to 3 now your action result parameter is not id but interID so either do

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

or change the interID to ID

public JsonResult InternDetail(int ID)

you can also configure your route

Sign up to request clarification or add additional context in comments.

1 Comment

That did it . Thanks for the explaination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.