2

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();
       }
1
  • This is really strange! Look at this fiddle it worked for me correctly. It might give you some tip to the resolution. Commented Nov 24, 2015 at 8:10

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

6 Comments

Hi..thanx for the answer. Url.Action did not work. :(
When I typed url in address bar, i get to controller. and link shows correct address when I move mouse over that link...
@Gokhale That's strange. What is the name of your controller where Copy action located?
It returns 'The resource can not be found' Requested URL: /Item/Copy/001020002
@Gokhale Post the URL along with your route configurations.
|

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.