Inline markup blocks cannot be nested. Only one level of inline markup is allowed. MVC RAZOR

拈花ヽ惹草 提交于 2019-12-30 08:14:23

问题


I one one modal window with telerik grid inside. But i need to render images in my grid so as i understand i cant use @ twice. Here is blog post about this issue Link

Can someone assist me please.

My Code

@{  Html.Telerik().Window()
    .Name("images")
    .Title("Select an Image")
    .Content(@<text>

@(Html.Telerik().ComboBox()
            .Name("AjaxComboBox66")
            .AutoFill(true)
            .SelectedIndex(0)
            .BindTo(new SelectList(Model.PhotoFolders, "ID", "Name"))
            .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.StartsWith))
            .HighlightFirstMatch(true)
            .ClientEvents(events => events
                .OnChange("onChange")
            )
      )

      @(Html.Telerik().Grid<AjaxImages>()
    .Name("Grid")
    .DataKeys(keys => keys.Add(c => c.ID))
  .Columns(columns =>
  {
      columns.Template(
          @<text>
               <img src='@item.Url' /> 
//Here is my error. I need helper function
           </text>

).Title("Picture");

  })

                              .DataBinding(dataBinding => dataBinding.Ajax().Select("GetImages", "UserProducts"))

                      .Scrollable(scrolling => scrolling.Enabled(true))
                      .Sortable(sorting => sorting.Enabled(true))
                          .Pageable(paging => paging.Enabled(true).PageSize(20).Total(100).Style(GridPagerStyles.NextPreviousAndNumeric))
                      .Filterable(filtering => filtering.Enabled(true))
                      .Groupable(grouping => grouping.Enabled(false))
                      .EnableCustomBinding(true)

                      .Footer(true))
              </text>)
    .Width(400)
    .Draggable(true)
    .Modal(true)
    .Visible(false)


    .Render();
} 

My GetImages function return me json with "ID" and "URL".


回答1:


In these situations the MVC Razor helper function can be used. Create the helper function with the grid control definition, in this case RenderGrid().

@helper RenderGrid()
{
     @(Html.Telerik().Grid<AjaxImages>()
     .Name("Grid")
     .DataKeys(keys => keys.Add(c => c.ID))
     .Columns(columns =>
     {
         columns.Template(
         @<text>
             <img src='@item.Url' /> 
         </text>
         ).Title("Picture");
     })
     .DataBinding(dataBinding => dataBinding.Ajax().Select("GetImages", "UserProducts"))
}

Call the helper function inside the window's content definition. The helper functions can be called multiple times if needed.

    @{Html.Telerik().Window()
      .Name("images")
      .Title("Select an Image")
      .Content(
       @<text>
          @RenderGrid()
       </text>)
      .Width(400)
      .Draggable(true)
      .Modal(true)
      .Visible(false)
      .Render();
} 



回答2:


In previous MVC @helper was used as a workaround for inability to nest @<text> tags. But in MVC CORE @helper is omitted. Read more here:

https://github.com/aspnet/Razor/issues/715



来源:https://stackoverflow.com/questions/10684025/inline-markup-blocks-cannot-be-nested-only-one-level-of-inline-markup-is-allowe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!