I am stucked in a situation where I want to avoid user to navigate to a View by entering URL into the Browser.But can navigate to that view on clicking to a button whose action navigate to that view.
For eg:I have a href link to an ActionResult(Create).I want the user to navigate to this view(Create) when clicked on that link but not when it enters the url in the browser like (/Create).
I found some solutions on this portal like:
1)Making the ActionResult private-But this results in Http:404 Page not found Error by both entering the URL in the browser and on clicking the link which navigates to Create ActionResult.
referred links: Is it i possible to prevent certain PartialViews from being served if requested directly? 2)Using DataAnnotaion [ChildActionOnly] on the ActionResult Method.But this also doesnot gave me the desired result,it gave me an error too.The same error HTTP:404.
3)I tried using ControllerContext.IsChildAction but it alwayz return value false whether i navigate to this ActionResult on link click or entering the URL so I cant judge what to do.if it returns true in one case or false in other I would have solved my problem by redirecting in any case.
Asp.net mvc How to prevent browser from calling an action method?
help me Guys..