Monica
Monica

Reputation: 141

send value to controller using html.actionlink

I am passing value from Html.ActionLink to the controller. But the problem is in controller, value is not being fetched. I don't know what is the problem.

Here is my code :

View :

    @Html.ActionLink("Copy", "Copy", "Item", new { id = item.Item_code}, null)

Contoller :

       public ActionResult Copy(int id)
       {
                 // Logic here
                 return View();
       }

Upvotes: 2

Views: 4414

Answers (1)

user2771704
user2771704

Reputation: 6202

You HTMLhelper looks OK, so that's strange. Please check a route for this link. Also type in the expected URL in browser address bar and see if you can get to controller. Also check URL when your mouse over the link. Does it show correct link?

You could try to use Url.Action instead of Html.ActionLink helper like below:

<a href="@Url.Action("Copy", "Item", new { id = item.Item_code})"> Copy</a>

Update

Since you have ID like 001020002, try to change int type to string to see if it works that way:

   public ActionResult Copy(string id)
   {
             // Logic here
             return View();
   }

in View:

@Html.ActionLink("Copy", "Copy", "Item", new { id = item.Item_code.ToString()}, null)

Upvotes: 1

Related Questions