I would like to perform an MVC action only if the javascript is disabled.
To try to achieve this goal, I added a tag <noscript> in my html:
<noscript>
@Html.Action("BlogRss", "Home")
</noscript>
In my controller, follow the action
public PartialViewResult BlogRss()
{
return PartialView("_BlogRss", GetFeeds());
}
The problem is that the tag <noscript> does not affect the non-execution of the action.
The same is done with or without javascript enabled!
I know that everything inside the <noscript> will not be displayed if JavaScript is enabled.
<noscript>is a HTML tag, not a server tag, and will only function on the client side. The server will always render / execute any code you put between it – the client just won’t render / execute it.There aren’t any nice ways of detecting whether a client has JavaScript enabled or not from the server side. The most realistic way would be to use javascript / AJAX to set a hidden value or cookie (
document.cookie) and then use this value / cookie on the server side.