I'm very new to ASP .Net MVC, I bought the Pro ASP .Net MVC Framework book from Apress last week and it's proving to be very helpful.
The problem that I'm seeing so far is that almost all the example views are riddled with magic strings. I've managed to go through and figure out a few alternatives, but the code starts to get kinda difficult to read. For example:
<% using(Html.BeginForm("RemoveFromCart", "Cart")){ %>
<%= Html.Hidden("ProductID", line.Product.ProductID) %>
<%= Html.Hidden("returnUrl", ViewData["returnRrl"]) %>
<input type="submit" value="Remove" />
<% } %>
Becomes:
<% using (Html.BeginForm<CartController>(c => c.RemoveFromCart(null, line.Product.ProductID, (string)ViewData["returnUrl"]))) { %>
<input type="submit" value="Remove" />
<% } %>
I can get away with this example, because the first parameter to RemoveFromCart
is pulled from the session via a ModelBinder
, but it's not intuitive to read.
My concern is that I'm going to spend my time fighting the framework to avoid magic strings and in the process end up with mark up that's a pain to read. In peoples experience is this a valid concern and is there a reference on the web where there is a "magic string method" to "type safe method" lookup table?