My project uses .net core 2.0 MVC and I'm working with razor but I need some help.
I'm trying to replace this code:
<div class="form-group">
<label asp-for="Address" class="control-label"></label>
<input asp-for="Address" class="form-control" />
<span asp-validation-for="Address" class="text-danger"></span>
</div>
by a tag helper that lets me write something like:
<add-edit-form-group ##Address##></add-edit-form-group>
I already have made folder TagHelpers
add a file, and with this code it almost works, of course I need some help with passing arguments to the tag helper and then work on remove string and add the code.
The helper code is:
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
using WebApp.Models;
namespace WebApp.TagHelpers
{
public class AddEditFormGroupTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
StringBuilder html = new StringBuilder();
html.Append("<div class=\"form-group\">");
html.Append("<label asp-for=\"Address\" class=\"control-label\"></label>");
html.Append("<input asp-for=\"Address\" class=\"form-control\" />");
html.Append("<span asp-validation-for=\"Address\" class=\"text-danger\"></span>");
html.Append("</div>");
output.Content.SetHtmlContent(html.ToString());
}
}
}