I haven’t done MVC2 (or any MVC really) in over a year and while this works, I want to make sure it’s the best way.
I have a “splash” page that allows the user to choose what they want to work on; Interfaces, Events, Parameters or Tasks. The HTML is:
<a href="/Interfaces/Index">
<div id="homeInterfaces" class="homeLinks">
<h1>Interfaces</h1>
<h2>Create, Edit or Delete Interfaces</h2>
</div>
</a>
<a href="/Tasks/Index">
<div id="homeTasks" class="homeLinks">
<h1>Tasks</h1>
<h2>Create, Edit or Delete Tasks</h2>
</div>
</a>
<a href="/Parameters/Index">
<div id="homeParameters" class="homeLinks">
<h1>Parameters</h1>
<h2>Create, Edit or Delete Parameters</h2>
</div>
</a>
<a href="/Events/Index">
<div id="homeEvents" class="homeLinks">
<h1>Events</h1>
<h2>Create, Edit or Delete Events</h2>
</div>
</a>
The links work and go to the appropriate pages, but for whatever reason, I’m not sure if this is the proper way to go about it. I have controllers for each, the proper folders with the Index views for each. I don’t think I should be using Html.ActionLink, but maybe there’s something else I should be using. Any thoughts? Thanks.
Yes, you should be using a helper for these. This will ensure that your generated links use the appropriate routes, which will make your life much easier in the future if you do anything fancy with your URLs or deploy to a non-root path (i.e.
/)In your case, the easiest solution is to replace the URL with
@Url.Action. I’d use that overHtml.ActionLinkbecauseHtml.ActionLinkdoesn’t let you easily linkify content more complicated than simple text (e.g. your html).If you’re not using Razor, go switch to that first. It’s worth it. Or drop the
@sign and add some<%= ... %>.As @MichalFran notes, though, if it’s working now, you can always just start following this advice in the future and revisit what you’ve already done when/if you need to down the road.