Javascript Action有一个对象路由值为null

Javascript Action有一个对象路由值为null,javascript,c#,asp.net-mvc-5,Javascript,C#,Asp.net Mvc 5,我试图将两个参数传递给控制器,以便返回特定应用程序中当前用户的角色列表。然后使用此列表自动完成搜索框 我的问题是因为在我的Url.Action helper中,一个对象路由变量始终为空。代码位于局部视图上的脚本中,如下所示: <script type="text/javascript"> function roleFilter(element) { element.kendoAutoComplete({ dataSource: {

我试图将两个参数传递给控制器,以便返回特定应用程序中当前用户的角色列表。然后使用此列表自动完成搜索框

我的问题是因为在我的Url.Action helper中,一个对象路由变量始终为空。代码位于局部视图上的脚本中,如下所示:

<script type="text/javascript">
    function roleFilter(element) {
        element.kendoAutoComplete({
            dataSource: {
                transport: {
                    read: "@Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })"
            }
        }
        });
    }
</script>
我知道ViewBag包含正确的值,但是在这个脚本中它是空的,但是我可以在页面的其他地方用代码传递它。如果有人能帮忙,我们将不胜感激

全局部视图:

@(Html.Kendo().Grid<BUUK.BSS.Models.Role>()
    .Name("grid")
    .DataSource(dataSource => dataSource // Configure the grid data source
        .Ajax() // Specify that ajax binding is used
        .Read(read => read.Action("CurrentUserRoles_Read", "User",
            new
            {
                userName = ViewBag.UserName,
                applicationName = ViewBag.ApplicationName
            })) // Set the action method which will return the data in JSON format
            .PageSize(15)
     )
    .Columns(columns =>
    {
        columns.Bound(role => role.RoleName)
            .Filterable(filterable => filterable.UI("roleFilter"));
    })
          .Pageable() // Enable paging
          .Sortable() // Enable sorting
              .Filterable(filterable => filterable
                .Extra(false)

                .Messages(m => m.Info("Items with value equal to:")
                )
            ).Events(e => e.FilterMenuInit("filterMenuInit"))
        )

<p style="margin-top:5px;">
    @Html.ActionLink("Add Roles", "EditRoles", "User", new { applicationName =     ViewBag.ApplicationName, userName = ViewBag.UserName }, null)
</p>

<script type="text/javascript">
    function roleFilter(element) {
        element.kendoAutoComplete({
             dataSource: {
                transport: {
                    read: "@Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })"
            }
        }
        });
    }
</script>

而不是像上面那样。
applicationName
正确传递,但
用户名
null

查看由创建的url

 @Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })
在JavaScript中。它的格式可能不正确。尝试:

"@Html.Raw(Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName }))"

查看由创建的url

 @Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })
在JavaScript中。它的格式可能不正确。尝试:

"@Html.Raw(Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName }))"

查看由创建的url

 @Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })
在JavaScript中。它的格式可能不正确。尝试:

"@Html.Raw(Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName }))"

查看由创建的url

 @Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName })
在JavaScript中。它的格式可能不正确。尝试:

"@Html.Raw(Url.Action("FilterMenuCustomization_Roles", new { userName = ViewBag.UserName, applicationName = ViewBag.ApplicationName }))"


当输出到视图时,
ViewBag.ApplicationName
的内容是什么?你能调试它并看到它的价值吗?当我在URL中调试时,@DavidG视图中
ViewBag.ApplicationName
的内容是
amadeus
。操作它说它是
null
,但在其他地方
ViewBag.Application
按预期持有
amadeus
我不确定你要找的是什么URL?它是否为null视图中的每个部分或仅在
kendoAutoComplete
部分中?@DavidG仅在
kendoAutoComplete
视图包中的
ViewBag.ApplicationName
输出到视图时的内容是什么?你能调试它并看到它的价值吗?当我在URL中调试时,@DavidG视图中
ViewBag.ApplicationName
的内容是
amadeus
。操作它说它是
null
,但在其他地方
ViewBag.Application
按预期持有
amadeus
我不确定你要找的是什么URL?它是否为null视图中的每个部分或仅在
kendoAutoComplete
部分中?@DavidG仅在
kendoAutoComplete
视图包中的
ViewBag.ApplicationName
输出到视图时的内容是什么?你能调试它并看到它的价值吗?当我在URL中调试时,@DavidG视图中
ViewBag.ApplicationName
的内容是
amadeus
。操作它说它是
null
,但在其他地方
ViewBag.Application
按预期持有
amadeus
我不确定你要找的是什么URL?它是否为null视图中的每个部分或仅在
kendoAutoComplete
部分中?@DavidG仅在
kendoAutoComplete
视图包中的
ViewBag.ApplicationName
输出到视图时的内容是什么?你能调试它并看到它的价值吗?当我在URL中调试时,@DavidG视图中
ViewBag.ApplicationName
的内容是
amadeus
。操作它说它是
null
,但在其他地方
ViewBag.Application
按预期持有
amadeus
我不确定你要找的是什么URL?它是否为null视图中或
kendoAutoComplete
部分中的每个部分?@DavidG仅使用
@Html.Raw
kendoAutoComplete
会给我以下运行时异常:
JavaScript第68行出现严重错误,中的第33列http://localhost:59933/User/Roles?userName=chris.blair&applicationName=Amadeus&status=Active\n\nSCRIPT5017:正则表达式中的语法错误
,看起来像JavaScript语法错误,实际上与MVC无关。请尝试以下操作:console.log('@Url.Action(“FilterManuCustomization_Roles”),新建{userName=ViewBag.userName,applicationName=ViewBag.applicationName}')console.log('@Html.Raw(Url.Action(“FilterMenuCustomization_角色”,新的{userName=ViewBag.userName,applicationName=ViewBag.applicationName}'))并查看它们是否在您的标记内有所不同。这只是为了调试目的。操作提供:
/User/filtermanucustomization\u Roles?userName=chris.blair&;applicationName=Amadeus
和原始Url。操作提供:
/User/filtermanucustomization\u Roles?userName=chris.blair&applicationName=Amadeus
第一个在两个根值之间有
amp;
。这是否有显著差异?使用
@Html.Raw
会出现以下运行时异常:
中第68行第33列的JavaScript严重错误http://localhost:59933/User/Roles?userName=chris.blair&applicationName=Amadeus&status=Active\n\nSCRIPT5017:正则表达式中的语法错误
看起来像JavaScript语法错误,实际上与MVC无关。请尝试以下操作:console.log('@Url.Action(“FilterMenuCustomization_Roles”,new{userName=ViewBag.userName,applicationName=ViewBag.applicationName}))console.log('@Html.Raw(Url.Action(“FilterMenuCustomization_Roles”,new{userName=ViewBag.userName,applicationName=ViewBag.applicationName}'))并查看它们是否在您的标记内有所不同。这只是为了调试目的。操作提供:
/User/filtermanucustomization\u Roles?userName=chris.blair&;applicationName=Amadeus
和原始Url。操作提供:
/User/filtermanucustomization\u Roles?userName=chris.blair&applicationName=Amadeus
第一个在两个根值之间有
amp;
。这是否有显著差异?使用
@Html.Raw
会出现以下运行时异常:
中第68行第33列的JavaScript严重错误http://localhost:59933/User/Roles?userName=chris.blai