tag-helpers

ASP.NET mvc View with IEnumerable model and input tag helper

送分小仙女□ 提交于 2019-12-05 07:22:25
In this official ASP.NET Core tutorial , I can use an Input Tag Helper as shown below. But due to a known model binding issue of form elements in a foreach loop , I want to use for loop instead. Question : If I were to replace @foreach (var item in Model) with @for (int i=0; i < Model.Count(); i++) in the following View . What would be my asp-for in <input asp-for="???" /> ? For some reason, intellisense is not recognizing, e.g, Model[i].BlogId or @Model[i].BlogId @model IEnumerable<EFGetStarted.AspNetCore.NewDb.Models.Blog> @{ ViewBag.Title = "Blogs"; } <h2>Blogs</h2> <p> <a asp-controller=

ASP.NET Vnext Tag Helpers for Areas

放肆的年华 提交于 2019-12-04 21:14:27
I may use <a href='/Area/Controller/action'> </a> in asp.net vnext but just want to know whether we can use tag helpers like <a asp-controller="ControllerName" asp-action="ActionName" asp-area="AreaName"> to redirect to the specific file in the area. Will any one guide me how to redirect to a file in area using tag helpers.? Finally I got the answer from the following link which works well. <a asp-route-area="AreaName" asp-controller="ControllerName" asp-action="ActionName"> </a> github link Christoph Brückmann If you use ReSharper it's IntelliSense could also override the Tag Helpers. I

Manual Anti-Forgery Token Creation and Validation in ASP.NET 5

元气小坏坏 提交于 2019-12-04 13:10:00
问题 I am playing around with ASP vnext and AngularJS. I have set up a Web API, am using some controllers and am using angular to do some web-magic. I have followed most of this guide to get my project up and running: http://stephenwalther.com/archive/2015/01/29/asp-net-5-and-angularjs-part-6-security ... which works fine. I have set up my db and such and I have things working. I have the identity framework set up too but I am not using it as of yet. I want to post some data to the WebAPI. Which

Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

末鹿安然 提交于 2019-12-04 07:47:22
I've been reading about the new support for Tag Helpers in MVC 6 and now need to create my own. I see that the built in tag helpers for existing HTML elements are all prefixed with "asp-" For example: <a asp-controller="Home" asp-action="Index">Home</a> But what about my own custom tag helpers. Should I also prefix those with "asp-" to show that it is running on the server. Or should this be reserved for framework attributes? Should I create my own project/company named prefix instead? Is there any guidance on this subject that I have missed? Tag helpers that target existing HTML elements

ASP .Net Core Custom Tag Helper to Convert CamelCase Properties to spaces

半世苍凉 提交于 2019-12-03 15:16:44
Is it possible in ASP.Net Core to automatically convert camel case property names in view models to insert spaces into the corresponding labels when using tag helpers? If my view model looks like this... [Display(Name = "First Name")] public string FirstName { get; set; } [Display(Name = "Last Name")] public string LastName { get; set; } [Display(Name = "Referral Date")] public DateTime ReferralDate { get; set; } It seems like a lot of extra configuration applying data annotations such as [Display(Name = "First Name")] to simply insert a space between words. It would make sense that Tag

Manual Anti-Forgery Token Creation and Validation in ASP.NET 5

余生颓废 提交于 2019-12-03 08:56:36
I am playing around with ASP vnext and AngularJS. I have set up a Web API, am using some controllers and am using angular to do some web-magic. I have followed most of this guide to get my project up and running: http://stephenwalther.com/archive/2015/01/29/asp-net-5-and-angularjs-part-6-security ... which works fine. I have set up my db and such and I have things working. I have the identity framework set up too but I am not using it as of yet. I want to post some data to the WebAPI. Which also works fine, but now I want to do it while using anti forgery tokens. I have googled a lot and I

TagHelper for passing route values as part of a link

馋奶兔 提交于 2019-12-02 20:01:27
When specifying asp-controller and asp-action on a link, what's the syntax for also passing an id attribute? E.g. If I wanted to link to the edit URL for a given object, the required URL would be /user/edit/5 for example. Is there a method to achieve this using TagHelpers, or do we still have to fall back to @Html.ActionLink() ? You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp-action="Edit" asp-route-id="10" asp-route-foo="bar">Edit</a> I'd like to suggest a combination of the other two answers, but with a bit of extra clarification. You will use

C# Access child members of hierarchy with foreach

家住魔仙堡 提交于 2019-12-02 17:35:29
问题 I am trying to make Foreach work for the html razor below. At the end of the day, I want ShoppingCart to be a list of CartLines. I want to get rid of the [0] statement, and make it variable. Any solution or optimal method would help. Feel free to edit the class also. class ShoppingCart { public IList<CartLine> Items { get; } = new List<CartLine>(); public ShoppingCart() {} } public class CartLine { public int CartLineId { get; set; } public Product Product { get; set; } public int Quantity {

C# Access child members of hierarchy with foreach

一笑奈何 提交于 2019-12-02 09:34:54
I am trying to make Foreach work for the html razor below. At the end of the day, I want ShoppingCart to be a list of CartLines. I want to get rid of the [0] statement, and make it variable. Any solution or optimal method would help. Feel free to edit the class also. class ShoppingCart { public IList<CartLine> Items { get; } = new List<CartLine>(); public ShoppingCart() {} } public class CartLine { public int CartLineId { get; set; } public Product Product { get; set; } public int Quantity { get; set; } } @model IEnumerable<ShoppingCart> @foreach (var item in Model) { <tr> <td> @Html

Tag Helpers disabled in VS 2015

寵の児 提交于 2019-12-01 18:20:11
I am having trouble getting Tag Helpers enabled in my project. Here is a summary of the project setup: VS 2015 RC Community Edition. Project.json reference: Microsoft.AspNet.Mvc": "6.0.0-beta4 _GlobalImport.chtml has @addTagHelper"*,Microsoft.AspNet.Mvc.TagHelpers" No build errors or warnings. Must missing something, but I don't know what. UPDATE: Seems I am part of the way there. I added @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" to the _ViewStart.chtml. Razor is now processing things like <a asp-controller="Home" asp-action="Summary" title="Manage">TEST</a> as a link with a proper