简体   繁体   中英

What is an alternative in MVC to meta tag content url:?

I am working on an MVC project where I am using quite a bit of java script, I am trying to put the following code to my _Layout page:

<noscript>
    <meta http-equiv="refresh" content="0;url=/NoJScript" />
</noscript>

So I was following this tutorial step by step and the url=/NoJScript just doesn't take me to the controller method like it does for him when I shut off the java script in my browser. I just get a 404. I put the view in its place as well of course. I even tried putting the full path and still nothing. I read somewhere that I shouldn't even use the URL under the meta tag because there is unreliable in some browsers. So is there a code to automatically redirect me to my controller and action result method when java script is switched off in browser?

Here is the NoJScript controller :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pansense.Controllers
{
public class NoJScriptController : Controller
{
    //
    // GET: /NoJScript/
    [AllowAnonymous]
    public ActionResult NoJavaScript()
    {
        return View("NoJavaScript");
    }
}
}

Here is the view called the same way as its method NoJavaScript:

@{
ViewBag.Title = "JavaScript required";
Layout = null; // <= Important!
}

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My MVC App</title>

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

</head>
<body>
To use this application JavaScript is required.
</body>
</html>

You need to name your action to Index like he does in the tutorial instead of NoJavaScript . Or you can change your url to /NoJScript/NoJavaScript

Further clarification:

Currently, your url in the meta tag will point to the default action on the NoJScriptController which, unless you changed your route values, will be the Index action. So you need to either specify the NoJavaScript action in the meta tag's url, or rename the action to Index .

Note: if you rename the action, you also have to rename the View.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM