【问题标题】:Razor Syntax in Kendo TabstripKendo Tabstrip 中的 Razor 语法
【发布时间】:2017-05-18 14:10:53
【问题描述】:

我对这段代码有疑问,它显示了;编译过程中丢失错误。 我实际上是在尝试将 aspx 代码切换到 razor syntax mvc5 项目。该代码在 aspx 中工作,所以我不确定我在 razor 中做错了什么。任何帮助将不胜感激。

tabstrip.Add()
                                                      .Text(item.Title)
                                                      //.HtmlAttributes(new { tabindex = "-1" })
                                                      .Selected(true)
                                                      .Content(() =>
                                                      {

                                                          using (Html.BeginForm(null, null, FormMethod.Post, new { id = "tabForm" }))
                                                          {
                                                                @<div style="width:980px;min-height:562px;margin-left:0px;margin-right:0px">
                                                                <div>
                                                                    @Html.ValidationSummary(false);
                                                                    @RenderBody();
                                                                </div>

                                                                <div style="padding-top:30px; text-align:center;">
                                                                    @{
                                                                        string roStyle = ViewData[Constants.ReadOnly].ToString();
                                                                        string roMessage = "";
                                                                        string roButtonText = "Cancel";

                                                                        //if (helper_readonly.Value == "true")
                                                                        if (Model.helper_readonly == "true")
                                                                        {
                                                                            roStyle = "style='display:none;'";
                                                                            roMessage = "READ ONLY - changes are not saved";
                                                                            roButtonText = "Close";
                                                                        }
                                                                    }
                                                                    <table border="0" width="100%">
                                                                        <tr>
                                                                            <td style="width:30%;" align="left">
                                                                                <input type="button" id="ToggleDiagnosticsButton" value="Show Diagnostics" class="k-button cancel" style="display:none;" />
                                                                            </td>
                                                                            <td style="width:40%;" align="center">
                                                                                <input type="submit" id="SaveButton" value="Save" class="k-button" @disabled @roStyle />&nbsp;&nbsp;
                                                                                <input type="submit" id="CancelButton" value="@roButtonText" class="k-button cancel" onblur="LastOnBlur()" />
                                                                                <input type="submit" id="submithelper" value="Cancel" class="cancel" style="display:none;" />
                                                                            </td>
                                                                            <td style="width:30%;" align="right">
                                                                                &nbsp;&nbsp;<span style="color:Red;">@roMessage</span>
                                                                            </td>
                                                                        </tr>
                                                                    </table>

                                                                </div>

                                                                @Html.Hidden("NextActionHelper", Model.NextActionHelper);
                                                                @Html.Hidden("UserFormAction", Model.UserFormAction);
                                                                </div>
                                                          }
                                                      });

编译错误;缺失的是倒数第二行。

完整代码:

@(Html.Kendo()
              .TabStrip()
              .Animation(false)
              .Name("tabstripForms")
              .Events(events => { events.Select("onFormTabSelect"); })
              .Items(tabstrip =>
              {
                  foreach (var item in ViewData[Constants.ViewDataKey_ActionTabMenu] as
                                       List<BusinessEntities.DTO.Shared.MvcMenuItem>)
                  {
                      bool selected = item.Action.ToLower() == ViewData[Constants.ViewDataKey_CurrentAction].ToString().ToLower() ? true : false;
                      if (selected)
                      {
                          //helper_post_on_cancel.Value = item.PostBackOnCancel.ToString();
                          Model.helper_post_on_cancel = item.PostBackOnCancel.ToString();
                          //helper_post_on_tabselect.Value = item.PostBackOnTabSelect.ToString();
                          Model.helper_post_on_tabselect = item.PostBackOnTabSelect.ToString();

                          tabstrip.Add()
                                                  .Text(item.Title)
                                                  //.HtmlAttributes(new { tabindex = "-1" })
                                                  .Selected(true)
                                                  .Content(() =>
                                                  {

                                                      using (Html.BeginForm(null, null, FormMethod.Post, new { id = "tabForm" }))
                                                      {
                                                            @<div style="width:980px;min-height:562px;margin-left:0px;margin-right:0px">
                                                            <div>
                                                                @Html.ValidationSummary(false);
                                                                @RenderBody();
                                                            </div>

                                                            <div style="padding-top:30px; text-align:center;">
                                                                @{
                                                                    string roStyle = ViewData[Constants.ReadOnly].ToString();
                                                                    string roMessage = "";
                                                                    string roButtonText = "Cancel";

                                                                    //if (helper_readonly.Value == "true")
                                                                    if (Model.helper_readonly == "true")
                                                                    {
                                                                        roStyle = "style='display:none;'";
                                                                        roMessage = "READ ONLY - changes are not saved";
                                                                        roButtonText = "Close";
                                                                    }
                                                                }
                                                                <table border="0" width="100%">
                                                                    <tr>
                                                                        <td style="width:30%;" align="left">
                                                                            <input type="button" id="ToggleDiagnosticsButton" value="Show Diagnostics" class="k-button cancel" style="display:none;" />
                                                                        </td>
                                                                        <td style="width:40%;" align="center">
                                                                            <input type="submit" id="SaveButton" value="Save" class="k-button" @disabled @roStyle />&nbsp;&nbsp;
                                                                            <input type="submit" id="CancelButton" value="@roButtonText" class="k-button cancel" onblur="LastOnBlur()" />
                                                                            <input type="submit" id="submithelper" value="Cancel" class="cancel" style="display:none;" />
                                                                        </td>
                                                                        <td style="width:30%;" align="right">
                                                                            &nbsp;&nbsp;<span style="color:Red;">@roMessage</span>
                                                                        </td>
                                                                    </tr>
                                                                </table>

                                                            </div>

                                                            @Html.Hidden("NextActionHelper", Model.NextActionHelper);
                                                            @Html.Hidden("UserFormAction", Model.UserFormAction);
                                                            </div>
                                                      }
                                                  });

                                                                    }
                                                                    else
                                                                    {
                                                                        tabstrip.Add()
                                                                             .Text(item.Title)
                                                                             //.HtmlAttributes(new { tabindex = "-1" })
                                                                             .Selected(false)
                                                                             .Content(() =>
                                                                             {
                                                                                 @<div style="min-height: 562px;">
                                                                                    <div class="k-loading-mask" style="width:982px;height:562px;">
                                                                                        <div class="k-loading-image">
                                                                                        </div>
                                                                                    </div>
                                                                                </div>



                                                                             });
                                                                    }
                  }
              })
        )

【问题讨论】:

  • 您是否查看过TabStrip HtmlHelper controls 的文档。主要区别在于 ASPX 使用 &lt;%: Html.Kendo().TabStrip()... %&gt; 而 Razor 使用 @(Html.Kendo().TabStrip()...)
  • 是的..经历了所有这些。
  • 好吧编译错误已经告诉你问题是什么了,所以现在只是找到流氓;的一个案例。您能否发布完整的 TabStrip 定义(并格式化代码以使其更易于阅读)?
  • 和你提到的方式.. @(Html.Kendo() ... ) .... 看起来我在 .Content(() => { 中做错了什么这里 }); ..并且在代码的倒数第二行有红色波浪线...在编译期间我在同一行出现错误
  • @Sandman 修改帖子以包含整个代码..

标签: c# asp.net asp.net-mvc razor kendo-asp.net-mvc


【解决方案1】:

我认为您可能在倒数第二行添加了不必要的)(关闭.Items())。也冒昧地进行了格式化;)

@(Html.Kendo()
    .TabStrip()
    .Animation(false)
    .Name("tabstripForms")
    .Events(events => { events.Select("onFormTabSelect"); })
    .Items(tabstrip =>
    {
        foreach (var item in ViewData[Constants.ViewDataKey_ActionTabMenu] as List<BusinessEntities.DTO.Shared.MvcMenuItem>)
        {
            bool selected = item.Action.ToLower() == ViewData[Constants.ViewDataKey_CurrentAction].ToString().ToLower() ? true : false;
            if (selected)
            {
                //helper_post_on_cancel.Value = item.PostBackOnCancel.ToString();
                Model.helper_post_on_cancel = item.PostBackOnCancel.ToString();
                //helper_post_on_tabselect.Value = item.PostBackOnTabSelect.ToString();
                Model.helper_post_on_tabselect = item.PostBackOnTabSelect.ToString();

                tabstrip.Add()
                .Text(item.Title)
                //.HtmlAttributes(new { tabindex = "-1" })
                .Selected(true)
                .Content(() =>
                {
                    using (Html.BeginForm(null, null, FormMethod.Post, new { id = "tabForm" }))
                    {
                        @<div style="width:980px;min-height:562px;margin-left:0px;margin-right:0px">
                             <div>
                                 @Html.ValidationSummary(false);
                                 @RenderBody();
                             </div>

                             <div style="padding-top:30px; text-align:center;">
                                 @{
                                     string roStyle = ViewData[Constants.ReadOnly].ToString();
                                     string roMessage = "";
                                     string roButtonText = "Cancel";

                                     //if (helper_readonly.Value == "true")
                                     if (Model.helper_readonly == "true")
                                     {
                                         roStyle = "style='display:none;'";
                                         roMessage = "READ ONLY - changes are not saved";
                                         roButtonText = "Close";
                                     }
                                 }
                                 <table border="0" width="100%">
                                     <tr>
                                         <td style="width:30%;" align="left">
                                             <input type="button" id="ToggleDiagnosticsButton" value="Show Diagnostics" class="k-button cancel" style="display:none;" />
                                         </td>
                                         <td style="width:40%;" align="center">
                                             <input type="submit" id="SaveButton" value="Save" class="k-button" @disabled @roStyle />&nbsp;&nbsp;
                                             <input type="submit" id="CancelButton" value="@roButtonText" class="k-button cancel" onblur="LastOnBlur()" />
                                             <input type="submit" id="submithelper" value="Cancel" class="cancel" style="display:none;" />
                                         </td>
                                         <td style="width:30%;" align="right">
                                             &nbsp;&nbsp;<span style="color:Red;">@roMessage</span>
                                         </td>
                                    </tr>
                                </table>

                            </div>

                            @Html.Hidden("NextActionHelper", Model.NextActionHelper);
                            @Html.Hidden("UserFormAction", Model.UserFormAction);
                       </div>
                   }
               });
           }
           else
           {
               tabstrip.Add()
                   .Text(item.Title)
                   //.HtmlAttributes(new { tabindex = "-1" })
                   .Selected(false)
                   .Content(() =>
                   {
                       @<div style="min-height: 562px;">
                           <div class="k-loading-mask" style="width:982px;height:562px;">
                               <div class="k-loading-image">
                               </div>
                           </div>
                       </div>
                   });
           }
       }
   }          
)

【讨论】:

  • 但我需要右括号来关闭项目,第二个) 用于关闭@() .. 这就是代码应该正确的方式吗? @(Html.Kendo() .TabStrip() .Animation(false) .Name("tabstripForms") .Events(events => { events.Select("onFormTabSelect"); }) .Items(tabstrip => { ..一些代码.. }) )
  • 您是否尝试过上面的代码 sn-p 来代替您拥有的代码?
  • 是的,试过了,它在代码中显示了问题,确实必须在关闭时关闭它)
猜你喜欢
  • 2019-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多