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

后端 未结 2 1939
挽巷
挽巷 2021-01-11 22:32

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

<
相关标签:
2条回答
  • 2021-01-11 22:50

    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

    0 讨论(0)
  • 2021-01-11 23:08

    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();
    } 
    
    0 讨论(0)
提交回复
热议问题