Friday, October 3, 2014

The ActionName attribute is very powerful in Sitefinity

If you haven’t heard, Sitefinity allows for not only ASP.NET WebForms development but also ASP.NET MVC development. There are different modes to MVC development in Sitefinity: Classic, Pure, and Hybrid.  I think the most common would be hybrid.  If you have an existing site and add a new MVC widget, you’re probably going to use Hybrid.

Code in Hybrid mode is a mix of WebForms in your MasterPages and Razor ASP.NET MVC in your widgets.  The routes in Hybrid mode are mixed also.  I mean to say that the routes are built for WebForms to work first and MVC second. Because of this you need to pay attention to the ActionName attribute on your control ActionResults and also your form tags.
Your controller
   1: /// <summary>
   2: /// This is the success Action.
   3: /// </summary>
   4: [ActionName("Success")]
   5: public ActionResult Success()
   6: {
   7: LoginModel model = new LoginModel();
   8: return View(model);
   9: }
  11: [HttpPost]
  12: [ActionName("Success")]
  13: public ActionResult Success(LoginModel model)
  14: {
  15: if(ModelState.IsValid)
  16: {
  18: }
  19: return View(model);
  20: }

Note that we use the ActionName attribute “Success”.  Normally you don’t have to do this.  The ActionName is inferred from the method name.  In Sitefinity Hybrid mode this is not the case.

Your view
   1: @model SitefinityWebApp.Mvc.Models.LoginModel
   2: <h1>
   3: @ViewData["HeaderText"]
   4: </h1>
   5: @using (Html.BeginFormSitefinity("Success", "<NAME OF WIDGET>", FormMethod.Post))
   6: {
   8: }

In your MVC view, you’ll use the helper BeginFormSitefinity.  A good convention is to use the name of the widget as the form name and we need to use the ActionName attribute “Success” in this sample to match our controller.  Here we are posting a form with inputs.

I hope this explains the power of ActionName.  It is seldom used it normal MVC development but necessary to Sitefinity MVC development.

Monday, January 27, 2014

My New Home Away From Home

For those of my readers that have missed me, I’m going to try to write more in 2014.  So for my first post of the new year, I want to talk about what I’ve been doing the last 6 months.  I’ve been onboarding as Director of Application Development at Foundation 648, Inc. F648 is a 4 year old .NET shop here in Indiana.  It was started by Patrick Poer and Buck Brian.  After meeting them we just hit it off.  I’m still learning about all they did in the past and we are expanding our capabilities rapidly.  It’s really challenging and I’m having a heck of a great time.


We recently moved into some permanent space with room to grow.  The new address is 11711 N. Pennsylvania St, Suite 255, Carmel, IN 46032.  We currently have space for 5 or 6 more developers and can easily expand down the hall.  It’s a great environment and we are hiring.


Here are some pictures of the my new home away from home.  I have a really nice office and all the bruises have healed from moving desks.  We work hard at F648 and love to do everything ourselves. 


Go thru the main entrance in the rear.  There is retail in the front and office space in the back of 11711.



Take the elevator upstairs




After you get to the 2nd floor turn right




Suite Entry




Reception Area




Break room




Developer Pit








President’s Office with a door to the deck




My Office, no door but a great view