Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MVC Html ActionLink与Twitter引导不兼容';不能使用html属性进行javascript集成_Javascript_Asp.net Mvc_Twitter Bootstrap_Razor - Fatal编程技术网

MVC Html ActionLink与Twitter引导不兼容';不能使用html属性进行javascript集成

MVC Html ActionLink与Twitter引导不兼容';不能使用html属性进行javascript集成,javascript,asp.net-mvc,twitter-bootstrap,razor,Javascript,Asp.net Mvc,Twitter Bootstrap,Razor,我正在使用Eric Hexter等人的“TwitterBootstrap for MVC”开发一个应用程序框架 共享索引页面中的默认html.actionlink行为有一个小问题,它使用foreach循环提供发送到视图的匿名模型的列表 我试图为“id”添加一个html属性,在删除一行数据时,该属性将调用javascript模式 如果我尝试添加属性,routevalues变量将呈现为字符串。我尝试过使用IDictionary来处理html属性,但结果类似 在foreach循环之外创建actionl

我正在使用Eric Hexter等人的“TwitterBootstrap for MVC”开发一个应用程序框架

共享索引页面中的默认html.actionlink行为有一个小问题,它使用foreach循环提供发送到视图的匿名模型的列表

我试图为“id”添加一个html属性,在删除一行数据时,该属性将调用javascript模式

如果我尝试添加属性,routevalues变量将呈现为字符串。我尝试过使用IDictionary来处理html属性,但结果类似

在foreach循环之外创建actionlink可以让javascript按预期工作

代码(片段)最后一行是发生错误/混淆的地方:

@using BootstrapSupport
@model System.Collections.IEnumerable   
    <h4>@Model.GetLabel() <small>Listing</small></h4>
<table class="table table-striped">
    <caption></caption>
    <thead>
        <tr>
            @foreach (var property in Model.VisibleProperties())
            {
                <th>
                    @property.GetLabel()
                </th>
            }
            <th></th>
        </tr>
    </thead>
    @{ int index = 0; }
    @foreach (var model in Model)
    {
        ViewData[index.ToString()] = model;
        <tr>
            @foreach (var property in model.VisibleProperties())
            {
                <td>
                    @Html.Display(index + "." + property.Name)
                </td>                    
            }
            <td>
                <div class="btn-group">
                    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                        Action
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        @{
                            @Html.TryPartial("_actions", model)                            
                            var routevalues = model.GetIdValue();  
                            <li>@Html.ActionLink("Edit", "Edit", routevalues)</li>
                            <li>@Html.ActionLink("Details", "Details", routevalues)</li>
                            <li class="divider"></li>
                            <li>@Html.ActionLink("Delete", "Delete", routevalues, new { id = "mylink" })</li>
@使用BootstrapSupport
@模型System.Collections.IEnumerable
@Model.GetLabel()列表
@foreach(Model.VisibleProperties()中的var属性)
{
@property.GetLabel()
}
@{int index=0;}
@foreach(模型中的var模型)
{
ViewData[index.ToString()]=模型;
@foreach(model.VisibleProperties()中的var属性)
{
@Html.Display(索引+“+”属性.Name)
}
    @{ @Html.TryPartial(“\u actions”,model) var routevalues=model.GetIdValue();
  • @ActionLink(“编辑”、“编辑”、路由值)
  • @ActionLink(“详细信息”,“详细信息”,路由值)
  • @ActionLink(“Delete”,“Delete”,routeValue,new{id=“mylink”})
预期结果:

<li><a href="/Film/Delete/1" id="mylink">Delete</a></li>
  • 实际结果:

    <li><a href="/Film/Delete?Count=1&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D" id="mylink">Delete</a></li>
    
  • 当我尝试使用IDictionary(假设routevalues返回RouteValueDictionary)时,得到了一个稍微不同但相似的结果

    ---编辑以响应Satpal----

  • 有没有什么方法可以在不重新编写Eric Hexter的MVC Twitter Bootsrap mod背后的代码块的情况下获得预期的结果

    根据Satpal的帮助,工作的代码行如下:

    <li>@Html.ActionLink("Delete", "Edit", new RouteValueDictionary(routevalues), new Dictionary<string, object> { { "id", "mylink" } })</li>
    
  • @Html.ActionLink(“删除”、“编辑”、新建RouteValueDictionary(routevalues)、新建字典{{“id”、“mylink”})

  • 尝试使用初始值设定项语法将HTML属性作为
    字典传递

    @Html.ActionLink("Delete", "Delete",  routevalues, 
      new  Dictionary<string, object>{
      { "id", "mylink" }
      }
     )
    
    因此,您必须使用oveload

    ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>)
    
    ActionLink(HtmlHelper、String、String、RouteValueDictionary、IDictionary)
    
    Hi Satpal-我尝试了各种重载组合,但似乎都不起作用。我觉得更多的是TwitterBootstrap是如何开发的,而不是Razor语法/使用方面的问题。我已经将IDictionary生成的html添加到了这个问题中。@melkisadek,我认为它的Razor错误与其他人一样it.example:,试试
    新字典
    啊,太棒了-到另一篇文章的链接很有帮助。我用这本字典似乎合乎逻辑,但实际上很有用。我把完整的代码放在了问题的底部。谢谢!@melkisadek,即使我认为
    也会有用,但你每天都在学习。我有更新的答案以便将来帮助他人
    ActionLink(HtmlHelper, String, String, RouteValueDictionary, Object)
    
    ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>)