404.15找不到MVC4 RazorJS [英] 404.15 not found MVC4 RazorJS

查看:229
本文介绍了404.15找不到MVC4 RazorJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 RazorJS 在js文件我的 MVC4 应用程序使用剃刀语法@

I'm using RazorJS in my MVC4 application for using the Razor syntax "@" in the Js file.

// code:

@Html.RazorJSInclude("~/Scripts/Application/Transactions.js")
<button id="btnSearch" name="submit" type="button" onclick="Loadgrid();">Search</button>

在Transaction.js有LoadGridmehtod内。当我用我Transaction.js作为上述code将其抛出我误差没有这样的方法(Loadgrid)被发现。

The "Transaction.js" has "LoadGrid" mehtod inside. When i use my Transaction.js as the above code it throws me error as "No such method(Loadgrid) is found".

在浏览器中呈现的HTML显示像,

The rendered HTML in the browser shows like,

<SCRIPT src="/razorjs.axd?fn=/Scripts/Application/Transactions.js" type="text/javascript"></SCRIPT>

当我试着用这样的,

<script src="~/Scripts/Application/Transactions.js"></script>
@Html.RazorJSInclude("~/Scripts/Application/Transactions.js")

JS文件是由浏览器,但JS文件中的 AJAX 呼叫接受不获取调用,并抛出我下面的异常作为警告。

The js file is accepted by the browser but the ajax call inside the js file is not getting called and throws me the following exception as an alert.

IIS 8.0 Detailed Error-404.15-Not Found

一些HTML内容。

with some html content.

// code在js文件

//Code in js file

function Loadgrid() {

    $.ajax({
        url: '@Url.Action("LoadColumns", "Home")',
        data: { 'workflowId': '5' },
        datatype: 'json',
        type: 'GET',
        cache: false,
        success: OnComplete,
        error: function (xhr, status, error) {
                alert(xhr.statusText);
                window.location.href = '@Url.Action("LogOut", "Account")';
        }
    });
}

//控制器:

    public ActionResult LoadColumns(string workflowId)
    {
      return Content("Success");
    }

负载列方法不击中。在那里我错了?

The load columns method is not getting hit. Where i'm wrong?

仅供参考,

当在Ajax调用如 URL中使用的URL:/首页/ LoadColumns 的code炒菜很好,但只能在本地机器,而不是在服务器(在开发主机)。

When using the url in the ajax call like url: '/Home/LoadColumns' the code woks very well but only in local machine and not in server(host in dev).

该RazorJS版本的 0.4.3

The RazorJS version is 0.4.3

来源:JS文件里面剃刀

推荐答案

您指定数据类型:JSON在你的Ajax调用,但你的控制器动作返回内容(成功); ,其中的内容将是纯文本,这是不允许的,用的东西返回JSON(新{富=酒吧转变,巴兹=布莱什},JsonRequestBehavior.AllowGet),那么,你说你的脚本中的Ajax调用不是刚开叫,然后你说你检索警报,该警报:

You specify datatype: 'json' in your ajax call, but your controller action return Content("Success"); where Content will be plain text and it is not allowed, change with something return Json(new { foo = "bar", baz = "Blech" }, JsonRequestBehavior.AllowGet), then, you say the ajax call inside your script is not gettin called, then you say you retrieve an alert, this alert:

alert(xhr.statusText);

,以便按照预期的函数被调用。不要使用警报调试,试一下:

so your function is called as expected. Don't use alerts to debug, try:

console.log(error);

也是你的preferred开发工具网络选项卡会做那么一个更好的工作警报。

also the network tab of your preferred developer tools will do a better work then alerts.

在这里,你可以找到一个简单的工作示例 实现你的任务:

Here you can find a simple working example to achieve your task:

\\浏览\\首页\\ Index.cshtml

@Html.RazorJSInclude("~/Scripts/App/TestRazorJS.js")
<button id="btnSearch" name="submit" type="button" onclick="LoadFromRazor()">Search</button>

\\脚本\\应用程序\\ TestRazorJS.js

function LoadFromRazor() {
  $.ajax({
    url: '@Url.Action("Test", "Home")',
    datatype: 'json',
    type: 'GET',
    cache: false,
    success: function () { console.log('done'); },
    error: function (xhr, status, error) {
      console.log(status);

    }
  });
}

\\控制器\\ HomeController.cs

public ActionResult Test()
    {
      return Json(new { foo = "bar", baz = "Blech" }, JsonRequestBehavior.AllowGet);
    }

这正常工作。

这篇关于404.15找不到MVC4 RazorJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆