Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET MVC, is it possible to limit an action to be called only through RenderAction and not from the browser?

Tags:

asp.net-mvc

I have some actions that are only called from Html.RenderAction and I'd like to prevent these actions from being called directly using a URL.

Is it possible to see that the current request was made from a call to RenderAction? In that case I could create an IActionFilter for that.

like image 603
Michiel van Oosterhout Avatar asked Aug 02 '11 14:08

Michiel van Oosterhout


People also ask

What is a partial view in MVC?

A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.

How to render partial view in MVC?

To create a partial view, right click on the Shared folder -> click Add -> click View.. to open the Add View popup, as shown below. You can create a partial view in any View folder. However, it is recommended to create all your partial views in the Shared folder so that they can be used in multiple views.

What method is used to render HTML string in a view?

You can use the Html. Raw() method for that.


1 Answers

Add the [ChildActionOnly] attribute.

like image 98
SLaks Avatar answered Oct 04 '22 21:10

SLaks