As every one telling like if we decorated action method with [NonAction] attribute than we can't access that through URL and We can restrict this by using private right.
so we can do same thing by using childAction attribute also, than what is the difference between them ? when we should go for NonAction and when we should go for ChildAction?
geetha velusamyPosted Nov 9, 2021, 1:56 PM
Child Action:
A child action is an action that is invoked by using html.renderaction or html.action helper from inside of a view.Child actions are useful for creating entire reusable widgets which could be embedded into your views and which go through their independent MVC lifecycle.
@{
ViewBag.Title = "Index";
}
Index
@ViewBag.TempValue
@*
@Html.Action("ChildAction", "Home", new { param = "first" })
Non Action:
NonAction attribute makes an action non accessible from the navigation bar.
It's an attribute which is used on the methods which are defined by public access modifiers. Actually MVC Framework treats all public methods as URLs but in case you don't want this then you have to decorate a method with the non action attribute. The same thing may be achieved by making the method private.
Example:
using System.Web.Mvc;
namespace DemoMvcApplication.Controllers{
public class HomeController : Controller{
public string MyMethod1(){
return "
My Method 1 Invoked
";}
[NonAction]
public string MyMethod2(){
return "
My Method 2 Invoked
";}
}
}
Vinod PasiPosted Sep 28, 2019, 2:35 PM
Manas MohapatraPosted Nov 16, 2016, 1:26 AM