Tuesday, August 5, 2014

Error-Messages

 

Hi Folks

I encountered an error during an implementation of ChildActionOnly attribute in a MVC application .This error occurs when you don’t specified an ChildActionOnly attribute on an action of controller.

You can specified an action at View level as shown below :

Index.cshtml

 @Html.Action("ChildAction", "Home", new { param= "first" })




While the code given below placed at action level.


Note: I didn’t decorated the below action with ChildActionOnly.


HomeController:


 


   1:   public ActionResult ChildAction(string param)
   2:          {
   3:              ViewBag.Message = "Child Action called. "+ param;
   4:              return View();
   5:          }




and I decorated an action with  NonAction attribute as shown below:”



   1:   [NonAction]
   2:          public ActionResult ChildAction(string param)
   3:          {
   4:              ViewBag.Message = "Child Action called. "+ param;
   5:              return View();
   6:          }



an error prompts at View level:


 


image


 


To overcome on error shown above ,Kindly decorate action with childActionOnly attribute as depicted below in image:


 


   1:  [ChildActionOnly]
   2:         public ActionResult ChildAction(string param)
   3:         {
   4:             ViewBag.Message = "Child Action called. "+ param;
   5:             return View();
   6:         }
   7:   



 


Note: This is one of cause to this error.


 


To know more about MVC please go through with given below link.

MVC Articles
Enjoy Coding and Reading Smile

2 comments :