Reputation: 163
I cant understand how pass some data using Actionlink()
to controller
In my project there have a controller name ProductController
and a ActionResult
public ActionResult ShowProduct(string location)
{
return View(db.Products.Where(location=location).ToList());
}
and an index.cshtml
view page in index there have-
<span id="spn-deliveryloccookies">@ViewBag.deliveryloccookies</span>
I am trying to pass @ViewBag.deliveryloccookies
through
@Html.ActionLink("Cosmatics", "Cosmatics", "Product" new { location = @ViewBag.deliveryloccookies });
but data is not going.
Upvotes: 0
Views: 49
Reputation: 124
First you have to store the @ViewBag.deliveryloccookies
into some variable.
So I have one idea.
var deliveryloccookiesdata= '@(ViewBag.deliveryloccookies)';
Now In ActionLink write code as:
@Html.ActionLink("Cosmatics", "Cosmatics", "Product" ,new{location=deliveryloccookiesdata});
Hope this works!
Upvotes: 1