MVC 4, Keeping Convention over Configuration

I’ve found myself adding several actions methods to a controller, repeating the action method type, like for example, having more than one Index method at the controller. Of course, I add something like ProcessAIndex, ProcessBIndex, etc.

I believe that may not be according to MVC principle of convention over configuration, so think I should have more controllers. I also think I can use Areas to mitigate controllers proliferation I’ll get. Will investigate more and will keep updated.

Twitter Bootstrap Less package on MVC 4

I followed the excellent article from Maarten Sikkema, from Macaw

Very good as it shows how to use Web Essentials plugin for VS to compile Bootstrap LESS files into CSS files.

I was able to successfully publish the site to an Azure Website while keeping simple layout view. I like using a separated navigation bar partial view as to separate that part from the general layout.

 

MVC Views, Returning to the same view after edit

I’d like to share how to return the same view after adding or editing content to the current item.

I had the case where I was editing a transportation record where I can have one or more containers (in my example).

Since I’m modifying an specific transportation, in the get version of the ActionResult method, is a parameter, lets say:

 

public ActionResult Create(Guid id)
{
...
}

Once I make the addition, at the POST version of the ActionResult method, I want the user to stay at the same view, for current Transport. if I used something like:

...
return View("Create", TransportationId)
...

I got the user back to the same view (page) but he/she can still see the same values just entered before saving, which is confusing and made users to sometimes add containers records more than once. In order to solve that situation I used:

...
return RedirectToAction("Create", new {id=TransportationId})
...

RedirectToAction returns a response to the browser and causes it to make a GET request to Create Action. The new… part carries the route parameter (as parameters are included on route querystring.

This way, when users adds the container, he/she can see the same page but with empty values so can keep entering more containers without thinking previous save was not successful.

Cheers.

TEDx Managua

Participé en TEDx Managua como voluntario este recién pasado viernes 6 de septiembre.

Felicidades a los organizadores y ponentes, excelentes presentaciones. Diferente al TedXManagua del año pasado, esta vez hubieron 2 salas donde la audiencia pudo presenciar el evento. Esto aparte del streaming por Internet.

Pueden encontrar más información sobre el evento en su página en Facebook: TEDxManagua FB

Saludos.