tag-helpers

Radio Button Tag Helpers in ASP.NET 5 MVC 6

房东的猫 提交于 2019-11-29 05:19:32
问题 I don't see any tag helpers for radio buttons in ASP.NET 5 MVC 6. What's the right way of handling form elements where I need to use radio buttons? 回答1: There is a TagHelper for all the input types which includes the radio button type as well. Assuming you have a view model like this public class CreateUserVm { public string UserName { set; get; } public IEnumerable<RoleVm> Roles { set; get; } public int SelectedRole { set; get; } } public class RoleVm { public int Id { set; get; } public

.Net Core tag helper intellisense and color coding not working

江枫思渺然 提交于 2019-11-29 03:33:10
I am having issues with .NET core and tag helpers. The color coding and the intellisense are not displaying or being registered when I type in asp-for. I've tried creating a new solution in a separate instance, verified that the intellisense works, and then copied the project.json into the project that doesn't have working intellisense/color coding, and it doesn't fix the issue. Here is my project.json { "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final", "Microsoft.AspNetCore.Diagnostics": "1.0.0",

How to add link parameter to asp tag helpers in ASP.NET Core MVC

天大地大妈咪最大 提交于 2019-11-28 17:41:58
I have a lot of experience with ASP.NET MVC 1-5 . Now I learn ASP.NET Core MVC and have to pass a parameter to link in page. For example I have the following Action [HttpGet] public ActionResult GetProduct(string id) { ViewBag.CaseId = id; return View(); } How can I implement the link for this action using tag helpers? <a asp-controller="Product" asp-action="GetProduct">ProductName</a> Alex You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp-controller="Product" asp-action="GetProduct" asp-route-id="10"> ProductName</a> You might want to apply the

In MVC 6, how to code checkbox list in view and pass the checked values to the controller?

萝らか妹 提交于 2019-11-28 09:18:38
Sorry but most of my searches take me to old MVC codes. Any help will be appreciated. In MVC 6 with tag helpers, how do you code a set of checkboxes: Use tag helper for label so clicking it will toggle the checked value Save (Bind?) the checked value to the IsOptionSelected property Pass these checked values back to Controller after clicking Submit ? I was able to display the checkboxes with labels correctly, but I do not know how to pass the checked values back to the controller via the model. Right now, IsOptionSelected values are coming back as false. I was also able to make the html helper

Append QueryString to href in asp.net core Anchor Helper Tag

烈酒焚心 提交于 2019-11-28 07:32:17
问题 I am trying to add anything in the query of the request to anchors in the html result: Fictitious example: User makes a request (note that band and song could be anything, I have a route catering this request: template: "{band}/{song}"): http://mydomain/band/song?Param1=111&Param2=222 Now I want my anchors to append the query string part to the href of my anchors. So I tried something like this (note the 'asp-all-route-data'): <a asp-controller="topic" asp-action="topic" asp-route-band="iron

Nesting TagHelpers in ASP.NET Core MVC

和自甴很熟 提交于 2019-11-27 23:53:48
The ASP.NET Core TagHelper documentation gives the following example: public class WebsiteContext { public Version Version { get; set; } public int CopyrightYear { get; set; } public bool Approved { get; set; } public int TagsToShow { get; set; } } [TargetElement("website-information")] public class WebsiteInformationTagHelper : TagHelper { public WebsiteContext Info { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "section"; output.Content.SetContent( $@"<ul><li><strong>Version:</strong> {Info.Version}</li> <li><strong>Copyright

MVC 6 Tag Helpers Intellisense?

馋奶兔 提交于 2019-11-27 22:57:48
Is there supposed to be Intellisense for the new asp- tag helpers in Razor/MVC 6? I was following along on one of Shawn Wildermuth's courses on Pluralsight and everything functions properly, but I thought I should be getting intellisense when I start typing asp- as an attribute on a tag. If it should be there do you have any ideas on what might cause it to disappear? I'm using Visual Studio 2015 Community, and RC1-Final versions of the .Net dependencies for Kestrel, Mvc, and TagHelpers. Make sure you add "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final" to your project.json dependencies. You

How to access RouteData from an ASP.Net 5 Tag Helper in MVC 6

拥有回忆 提交于 2019-11-27 18:28:14
问题 I am trying to get hold of the current route so that I can highlight the active page in a set of links using a Tag Helper. The TagHelperContext doesn't give me access to anything useful. How can I get a reference to the RouteData? 回答1: I eventually found the answer described here: https://github.com/aspnet/Announcements/issues/28 You can import the ViewContext using property injection by using a new attribute. You need to create a property in you tag helper class like this: [ViewContext]

asp.net conditionally disable a tag helper (textarea)

ε祈祈猫儿з 提交于 2019-11-27 13:33:51
I want to enable or disable a textarea depending on a condition that evalueates from the model, and I am using the textarea tag helper. In other words, something like this: <textarea asp-for="Doc" @(Model.MustDisable ? "disabled" : "")></textarea> But I got the following design-time error: The tag helper 'textarea' must not have C# in element's attribute declaration area. Then I tried: <textarea asp-for="Doc" disabled='@(Model.MustDisable ? "disabled" : "")'></textarea> which did not show any design time error but it renders like this: Model.MustDisable==true renders disabled='disabled' AND

MVC 6 Tag Helpers Intellisense?

旧城冷巷雨未停 提交于 2019-11-27 04:37:15
问题 Is there supposed to be Intellisense for the new asp- tag helpers in Razor/MVC 6? I was following along on one of Shawn Wildermuth's courses on Pluralsight and everything functions properly, but I thought I should be getting intellisense when I start typing asp- as an attribute on a tag. If it should be there do you have any ideas on what might cause it to disappear? I'm using Visual Studio 2015 Community, and RC1-Final versions of the .Net dependencies for Kestrel, Mvc, and TagHelpers. 回答1: