Using ASP.NET Controls in WebMatrix cshtml Pages

I create a site using WebMatrix using razor syntax in .cshtml files. However, I’m stumped about how I can use the usual set of asp.net controls that are in the toolbar in Visual Studio - for example: a calendar, a panel, a list of radio buttons, etc ... Can I use these or you Do you use only assistants with a razor?

+4
source share
3 answers

You cannot use ASP.NET controls with the /.cshtml razor. ASP.NET controls work with the ASP.NET WebForms viewer. A razor is a fundamentally different viewing mechanism than web forms.

If you really want to use the "old" controls, go to the .aspx pages. If this is not an option, take a look at a user interface library such as jQuery UI . This should give you a similar set of controls.

Note that there are a lot of controls in the razor, such as a switch list, out of date. Creating the same behavior requires only a few lines of markup, but without problems with file binding.

+3
source

As an alternative tool, you can use Telerik Tabstrip and transfer the .csHtml file as a partial view. Something like that:

@{ Html.Telerik().TabStrip() .Name("TabStrip") .Items(tabstrip => { tabstrip.Add() .Text("My First tab") .Action("Index", "ControllerName") .ImageUrl("~/Content/Common/Icons/Suites/mvc.png") .Content( @Html.Partial("csHtmlName_1", (List<TypeOfYourData>)ViewData["NameOfrelatedView"]).ToString() ); tabstrip.Add() .Text("My Second Tab") .Action("secondAction", "ControllerName") .ImageUrl("~/Content/Common/Icons/Suites/sl.png") .Content(@Html.Partial("csHtmlName_2", (List<TypeOfYourDate>)ViewData["NameOfrelatedView"]).ToString() ); }) .SelectedIndex(0) .Render(); } 

Please note that you need to install MVC Telerik first (it's free :) and OpenSource)

+2
source

You cannot use server controls in ASP.NET web pages. It was designed as an alternative to web forms.

You can use plain HTML, or you can use a range of HTML helpers that work similar to those found in MVC (without ModelBinding).

+1
source

Source: https://habr.com/ru/post/1343396/


All Articles