Using ASP.NET controls in WebMatrix cshtml pages
I am building a site with WebMatrix using the razor syntax in .开发者_如何学运维cshtml files. However I'm stumped as to how I can use the normal set of asp.net controls that are found in the toolbox in Visual Studio - eg: calendar, panel, radio button list etc... Is it possible to use these or can you only use Helpers with razor?
You cannot use ASP.NET controls with razor / .cshtml. ASP.NET controls work with the ASP.NET WebForms view engine. Razor is a fundamentally different view engine than web forms.
If you really want to use the 'old' controls, switch to .aspx pages. If that's not an option, look into a UI library like jQuery UI. That should give you a similar set of controls.
Note that in razor a lot of controls like radio button list are obsolete. It takes just a few lines of markup to create the same behavior, without the databinding hassle though.
As an alternative tool, you can use Telerik Tabstrip and pass your .csHtml file as a partial view to it. Some thing Like this:
@{ 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)
You can't use Server Controls in ASP.NET Web Pages. It has been designed as an alternative to Web Forms.
You can use plain HTML or you can use the range of HTML helpers which work in a similar way to the ones in MVC (without the ModelBinding).
精彩评论