Nyprez Nyprez - 18 days ago 8x
C# Question

Return bool from view/ActionLink to method - Asp.Net MVC

I've to pass a bool inside ->

"@Html.ActionLink(" ", "Like", new { id = Model.Id @*, Pass bool value here *@}".
My model doesn't contain a bool property nor can I add it(database first) or replace the model with a ViewModel. Is it still possible to pass a bool value to my method somehow?

My method Like signature takes a
Guid Id
and a
in parameter.

Can I somehow pass bool:

@Html.ActionLink("Like!", "Like", new { id = Model.Id, @* true bool*@}
@Html.ActionLink("Disike!", "Like", new { id = Model.Id, @*false bool*@}


public ActionResult Like(Guid id, bool getBool)
if (getBool == true){

return Content("Liked!");

}else if (getBool == false){

return Content("Disiked!");

Any idea how to pass a bool value from view to controller?

Amy Amy

You pass a bool the same way you pass your model id:

@Html.ActionLink("Like!",   "Like", new { id = Model.Id, getBool = true})
@Html.ActionLink("Disike!", "Like", new { id = Model.Id, getBool = false})

Ultimately there's nothing special about Model.Id. It's just a Guid. Values passed in don't have to come from anywhere in particular. Just pass in whatever.