10

I am using Telerik's UI for ASP.NET widgets. Most of these widgets have multiple configuration options. In .cshtml file i configure these widgets on multiple lines for readability.
For example below is the configuration for Grid widget.

<div class="row">
    <div class="col-md-12">
        @(Html.Kendo().Grid<ResultModel>()
            .Name("SearchGrid")            
            .Columns(col =>
            {
                col.Bound(p => p.DocumentID);
                col.Bound(p => p.UploadDate);
                col.Bound(p => p.DocumentType);
                col.Bound(p => p.ProcessStatus);                
                col.Bound(p => p.StateProvince);
                col.Bound(p => p.Error);                
                col.Bound(p => p.Notes);
            })
            .AutoBind(false)
            .Pageable()
            .Sortable()
            .Resizable(resize => resize.Columns(true))
            .Scrollable()
            .Sortable(sortable => sortable
                .AllowUnsort(true)
                .SortMode(GridSortMode.MultipleColumn))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(50)
                .ServerOperation(true)
                .Read(read => read.Action("Search", "Search"))
       ).Deferred())
    </div>
</div>

After editing cshtml file i press Control + K + D to auto format. Visual studio properly formats the html and anything configured in one line. But any widget that is configured on multiple lines gets indented by one tab. So in above case everything from .Name("SearchGrid") to ).Deferred())) gets indented by one tab.

The problem is every time i edit cshtml i press Control + K + D to format edited cshtml, but that causes all other widgets to indent by one tab. and eventual all these widgets move to extreme right of the page

Steve Greene
  • 12,029
  • 1
  • 33
  • 54
LP13
  • 30,567
  • 53
  • 217
  • 400
  • Yeah, this is very annoying. I wish I could somehow put an indicator or something not to reformat certain chunks of code. – Steve Greene Apr 19 '18 at 20:45
  • @SteveGreene I haven't received any reply from anyone so i thought i am the only one who is having this annoying issue :) – LP13 Apr 19 '18 at 20:53
  • I have found that if I add something to a kendo widget, it autoformats so I have gotten into the habit of doing an immediate CTRL-Z which undoes the formatting, but leaves my change. Checking if resharper might help. – Steve Greene Apr 19 '18 at 21:10
  • Anyone found a solution? Its pretty damn annoying. – Reafidy Jun 22 '18 at 05:19
  • Yeah, this has been an issue since I last used telerik controls about 4 years ago. Seems like it's still going on in 2018 :-/ – Hunter Nelson Oct 31 '18 at 19:26
  • @Reafidy Solution coming in VS 2019: https://developercommunity.visualstudio.com/content/problem/323902/razor-multiline-html-helper-formatting-indent-issu.html – Steve Greene Jun 20 '19 at 15:46

3 Answers3

0

I found a solution. Use { } after the @ for multiline Kendo Razor and it's unaffected by multiple Control + k + d.

@{
(Html.Kendo().DropDownList()
.Name("animatorEntityDropDownList")
.DataTextField("EntityName")
.DataValueField("EntityID")
.OptionLabel("- Select -")
.Events(e =>
{
e.Select("onSelectAnimatorEntityDropDownList");
})
.HtmlAttributes(new { style = "width:300px" }))
}
Nick Gallant
  • 285
  • 1
  • 3
  • 12
  • Me neither, the code doesn't show any errors but when I load the page the grids aren't showing. – Hunter Nelson Oct 31 '18 at 19:27
  • 2
    @HunterNelson Solution coming in VS 2019 https://developercommunity.visualstudio.com/content/problem/323902/razor-multiline-html-helper-formatting-indent-issu.html – Steve Greene Jun 20 '19 at 15:47
0

If you use non-rendering code block, you should call Render method.

@{
    Html.Kendo().NumericTextBox()
        .Name("myTextbox").Format("#")
        .Render();
}

VS 2017 won't indent the lines in the non-rendering code block when you auto format the document. (curly brackets)

@(
    Html.Kendo().NumericTextBox()
        .Name("myTextbox").Format("#")
)

VS 2017 will indent the lines in a regular block when you auto format the document. (round brackets)

Laszlo Boke
  • 1,319
  • 1
  • 10
  • 22
0

I work with VS2017 (asp.net core 2.2), use Devextreme controls and have exactly the same problems.
The only (very ugly and bad) "workaround" I found is, to write the whole code on ONE line. Details see link below: Link to SO posting

FredyWenger
  • 2,236
  • 2
  • 32
  • 36