Hello all, I decided to open a new thread which I could use to ask questions about how to customize this new MVC application I created https://www.daniweb.com/web-development/aspnet/threads/497464/much-simpler-first-mvc-application, add HTML and change the default look and feel. If the mods are OK with that, I was thinking to use this thread as a general one and pop in any questions related to that when I get stuck, rather than create a new thread every time about the same app. I hope it is OK.
In fact here is the first question.
I'm trying to customize the Book Index view and add a link from there to the Review Index view, saying something like "Go to reviews". I had a good look online, my understanding is that rather than using hardcoded HTML, it is better to use HTML helpers, and so I did and created this <div class="link">@Html.ActionLink("Go to Reviews", "Review")</div>
I read that this helpers can take several parameters, but I thought I'd do with two, the link text and the controller name. Unfortunately when I try that - remember that I'm in the Book view - the URL becomes localhost/xxxx/Book/Review rather than the localhost/xxxx/Review I was expecting, so it's appending the review controller at the end of the URL the link sits in. Had look online of course, some people say that the routing needs amending and remove the controller part, but isn't that a bit excessive? Then, in the list of possible parameters, I found the routevalue, 3rd parameter, so I changed the above to <div class="link">@Html.ActionLink("Go to Reviews", "Review", "Home")</div>
, but yet no joy, as the url now becomes localhost/xxxx/Home/Review, which, I would have thought was correct. Obviously not. NOt sure what else to try, any idea?
thanks
Recommended Answers
Jump to PostHave a look at T4MVC and @Url.Action
Jump to PostA quick difference I see is that Edit is a GET request, whereas Delete does a POST.
Update:
You posted an update while I posted this. Perhaps you need to put that ID in a hidden input to pass it back, but not entirely sure about that.
Jump to PostWith the submit you are posting back to your controller. If you set a debug break there, does it hit? If not, you may need the
[HttpPost]
data annotation (orAcceptVerbs
maybe, if you need both GET and POST).
Jump to PostTop Tip - look at T4MVC
@Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)
T4MVC lets you write
@Html.ActionLink("Delete Dinner", MVC.Dinners.Delete(Model.DinnerID))
https://github.com/T4MVC/T4MVC
https://visualstudiogallery.msdn.microsoft.com/8d820b76-9fc4-429f-a95f-e68ed7d3111a
All 13 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.