Quantcast
Channel: ASP.NET Core
Viewing all 9386 articles
Browse latest View live

Changing a PageModel property without using handler in Razor Pages

$
0
0

I'm developing a web application using Asp.Net Core Razor Pages.On the page model I have the following property:

  public class SchoolModel : PageModel
{
    [BindProperty]
    public School SchoolEdit { get; set; }

I'd like to change the Logo property of SchoolEdit(of type School) when I click a button on the form without having the form posted.How can I accomplish this? Here's the razor page code:

@if (Model.SchoolEdit.Logo != null)
   {<button class="btn btn-danger" asp-page-handler="RemovePhoto"><span aria-hidden="true">&times;</span></button>                      
   }


How to bind sales header model to collection of sales Footer on SalesOrder controller using ASP.NET core 2.1?

$
0
0

Problem

How to bind sales header Model to collection of sales Footer on SalesOrder controller using asp.net core 2.1 ?

I work on project have Sales Order form this form contain to :

salesHeader model

salesFooter model

so that i already have model Sales Header have navigation property to Sales Footer as following

SalesHeader Model

public int SalesOrderNo { get; set; }
  public int SalesYear { get; set; }
  public ICollection<SalesFooter> SalesFooters { get; set; }


SalesFooter Model
public int SalesOrderNo { get; set; }
public int Quantity { get; set; }
public int UnitPrice { get; set; }


How to get collection of sales footer on :

on Edit action of sales Order controller how to get collection of sales footer ?

on Edit view(get) sales Order controller how to get collection of sales footer ?

What I have tried:

Repository

public T GetById(int Id)
        {
            return dbSet.Find(Id);
        }
public class SalesOrderController : Controller
    {
        private readonly IrepositoryTab<SalesHeader> _repositoryHeader;
        public  SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter)
        {
            this._repositoryHeader = SalesHeader;
            this._repositoryFooter = SalesFooter;

        }

//get
//Edit Action of sales Order Controller 

public IActionResult Edit(int? id)
       {

           var SalesHeader = _repositoryHeader.GetById(id);
          //How to bind with sales footer
           return View();

       }

on Edit view of Sales Order Controller

 <div class="form-group"><label asp-for="SalesOrderNo" class="control-label"></label><input asp-for="SalesOrderNo" class="form-control" /><span asp-validation-for="SalesOrderNo" class="text-danger"></span></div><div class="form-group"><label asp-for="SalesYear" class="control-label"></label><input asp-for="SalesYear" class="form-control" /><span asp-validation-for="SalesYear" class="text-danger"></span></div>
//How to bind Sales Header with Sales Footer

on view of sales
Header

Web server doesn't see my controllers and gives 404 error

$
0
0

Hi all,

I published my web site via web deployment (to a2hosting).

However some controllers turn 404 error and I couldn't find what is the reason behind it.

Some says controller itself may cause an error and because I don't have built-in error page it may give 404 error. But I also couldn't find what is wrong with my controller.

Because it seems ok in my localmachine with local db.

Update: I tried to connect from my localmachine to webserver db

and got this error in debug mode

MySql.Data.MySqlClient.MySqlException: 'SELECT command denied to user 'evrak_root'@'85.110.148.234' for table 'gonderenler''

I checked web site and evrak_root user has all the accesses like SELECT and so on but still I got this error.

Which nuget packages are must for Web deployment

$
0
0

Hi all,

I have a .net core mvc app with MySQL entitity framework. I am having difficulties while deploying it and I wanted to be sure to include all necessary packages.

I have 

Microsoft.AspNetCore.App,

Microsoft.NETCore.App,

Microsoft.EntityFrameworkCore

Microsoft.EntityFrameworkCore.Tools

MySql.Data and MySql.Data.EntityFrameworkCore

installed 

Do I need anymore like Microsoft.AspNet.WebPages ?

Best bundling and minifying package and usage.

$
0
0

Hi all,

There are lots of options out there for bundling and minifying.

But one of them will be the most useful. Could you tell me which one is the best (for you ) and how can I use it.

I liked this one very much https://webpack.js.org/ it looks pretty.

however this one is also looking very popular https://gulpjs.com/ 

what do you think?

Difficulty in running Asp.net core web app in solution that previously contained asp.net apps

$
0
0

Dear All,

I have a solution that contains loasd of my asp.net project as a matter of fact I started building this solution with VS2013 before asp.net core came out. But since I have vs 2017. I copied the solution to the VS 2017 project folder. Right now I would to start a new project which suppose to be a asp.net core web application. But I usually have difficulties adding .net core project to this solution. I have added one and I can not run the web application. each time I try IIS just tends to freeze. I ended up with this message below

<div class="content-container">

HTTP Error 502.3 - Bad Gateway

The specified CGI application encountered an error and the server terminated the process.

</div> <div class="content-container">

Most likely causes:

  • The CGI application did not return a valid set of HTTP errors.
  • A server acting as a proxy or gateway was unable to process the request due to an error in a parent gateway.
</div> <div class="content-container">

Things you can try:

  • Use DebugDiag to troubleshoot the CGI application.
  • Determine if a proxy or gateway is responsible for this error.
</div> <div class="content-container">

Detailed Error Information:

<div id="details-left">
Module   AspNetCoreModule
Notification   ExecuteRequestHandler
Handler   aspNetCore
Error Code   0x80072ee2
</div> <div id="details-right"></div> <div>Please what do I do to ensure that I can have my asp.net core project within this solution.   Please  I would appreciate swift response cos the client is already on my case.</div> <div></div> <div>Thanks alot.</div>
</div>

No data saved in the partial view!

$
0
0

Hi

I'm trying to save data updated on the partial view called in Edit action.

I have these models:

Nz Class:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace NozCoreWebApp5.Models
{
    public partial class Nz
    {
        public Nz()
        {
            Mkh = new HashSet<Mkh>();
        }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#########}")]
        public decimal TxtId { get; set; }
        public int Sn { get; set; }
        public string FullName { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime? BirthDate { get; set; }
public int SexCode { get; set; } public string InsertUser { get; set; } [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")] public DateTime InsertDate { get; set; } public ICollection<Mkh> Mkh { get; set; } } }

Mkh Class: (child for Nz)

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace NozCoreWebApp5.Models
{
    public partial class Mkh
    {
        public int Sn { get; set; }
        public decimal TxtId { get; set; }
        public int MkhCode { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime MkhDate { get; set; }
        public int Days { get; set; }
        public string Notes { get; set; }
        public string InsertUser { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime InsertDate { get; set; }


        public MkhType MkhCodeNavigation { get; set; }
        public Nz Txt { get; set; }
    }
}

MkhType Calss: (Parent of Mkh)

using System;
using System.Collections.Generic;

namespace NozCoreWebApp5.Models
{
    public partial class MkhType
    {
        public MkhType()
        {
            Mkh = new HashSet<Mkh>();
        }

        public int MkhCode { get; set; }
        public string MkhName { get; set; }
        public string InsertUser { get; set; }
        public DateTime InsertDate { get; set; }

        public ICollection<Mkh> Mkh { get; set; }
    }
}

and I have this context:

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace NozCoreWebApp5.Models
{
    public partial class NozContext : DbContext
    {
        public NozContext()
        {
        }

        public NozContext(DbContextOptions<NozContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Mkh> Mkh { get; set; }
        public virtual DbSet<MkhType> MkhType { get; set; }
        public virtual DbSet<Nz> Nz { get; set; }
        public virtual DbSet<Sex> Sex { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer("Server=My-PC\\SQLEXPRESS;Database=Noz;Trusted_Connection=True;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            modelBuilder.Entity<Mkh>(entity =>
            {
                entity.HasKey(e => e.Sn);

                entity.ToTable("Mkh");

                entity.Property(e => e.Sn).HasColumnName("sn");

                entity.Property(e => e.Days).HasColumnName("days");

                entity.Property(e => e.InsertDate)
                    .HasColumnName("insert_date")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.InsertUser)
                    .IsRequired()
                    .HasColumnName("insert_user")
                    .HasMaxLength(20)
                    .HasDefaultValueSql("(N'any')");

                entity.Property(e => e.MkhCode).HasColumnName("Mkh_code");

                entity.Property(e => e.MkhDate)
                    .HasColumnName("Mkh_date")
                    .HasColumnType("date");

                entity.Property(e => e.Notes).HasColumnName("notes");

                entity.Property(e => e.TxtId)
                    .HasColumnName("txt_id")
                    .HasColumnType("numeric(9, 0)");

                entity.HasOne(d => d.MkhCodeNavigation)
                    .WithMany(p => p.Mkh)
                    .HasForeignKey(d => d.MkhCode)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Mkh_Mkh_type");

                entity.HasOne(d => d.Txt)
                    .WithMany(p => p.Mkh)
                    .HasForeignKey(d => d.TxtId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Mkh_Nz");
            });

            modelBuilder.Entity<MkhType>(entity =>
            {
                entity.HasKey(e => e.MkhCode);

                entity.ToTable("Mkh_type");

                entity.Property(e => e.MkhCode).HasColumnName("Mkh_code");

                entity.Property(e => e.InsertDate)
                    .HasColumnName("insert_date")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.InsertUser)
                    .IsRequired()
                    .HasColumnName("insert_user")
                    .HasMaxLength(20)
                    .HasDefaultValueSql("(N'any')");

                entity.Property(e => e.MkhName)
                    .IsRequired()
                    .HasColumnName("Mkh_name")
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<Nz>(entity =>
            {
                entity.HasKey(e => e.TxtId);

                entity.ToTable("Nz");

                entity.Property(e => e.TxtId)
                    .HasColumnName("txt_id")
                    .HasColumnType("numeric(9, 0)");

                entity.Property(e => e.BirthDate)
                    .HasColumnName("birth_date")
                    .HasColumnType("date");


                entity.Property(e => e.InsertDate)
                    .HasColumnName("insert_date")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.InsertUser)
                    .IsRequired()
                    .HasColumnName("insert_user")
                    .HasMaxLength(20)
                    .HasDefaultValueSql("(N'any')");

                entity.Property(e => e.SexCode).HasColumnName("sex_code");

                entity.Property(e => e.Sn)
                    .HasColumnName("sn")
                    .ValueGeneratedOnAdd();

                entity.HasOne(d => d.SexCodeNavigation)
                    .WithMany(p => p.Nz)
                    .HasForeignKey(d => d.SexCode)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Nz_sex");
            });

            modelBuilder.Entity<Sex>(entity =>
            {
                entity.HasKey(e => e.SexCode);

                entity.ToTable("sex");

                entity.Property(e => e.SexCode).HasColumnName("sex_code");

                entity.Property(e => e.SexName)
                    .IsRequired()
                    .HasColumnName("sex_name")
                    .HasMaxLength(10);
            });

            modelBuilder.Entity<Nz>()
            .HasAlternateKey(x => x.Sn).HasName("IX_Sn");
        }
    }
}

and the NzController actions:

    public class NzController : Controller
    {
        private readonly NozContext _context;

        public NzController(NozContext context)
        {
            _context = context;
        }
// ........ Some Code here .............
public async Task<IActionResult> Edit(decimal? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            //var Nz = await _context.Nz.FindAsync(id);
            var Nz = await _context.Nz
                         .Include(n => n.Mkh)
                         .ThenInclude(m => m.MkhCodeNavigation)
                         .FirstOrDefaultAsync(n => n.TxtId == id.Value);
            if (Nz == null)
            {
                return NotFound();
            }
            ViewData["SexCode"] = new SelectList(_context.Sex, "SexCode", "SexName", Nz.SexCode);
            return View(Nz);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Edit(decimal id, [Bind("TxtId,Sn,FullName,BirthDate,SexCode,InsertUser,InsertDate")] Nz Nz)
        {
            if (id != Nz.TxtId)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var Edited = new Nz()
                    {
                        TxtId = Nz.TxtId,
                        BirthDate = Nz.BirthDate,
                        InsertDate = Nz.InsertDate,
                        InsertUser = Nz.InsertUser,
                        FullName = Nz.FullName,
                        SexCode = Nz.SexCode,
                        Mkh = Nz.Mkh.Where(m => m.TxtId == Nz.TxtId).ToList(),
                    };
                    _context.Update(Edited);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NzExists(Nz.TxtId))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction(nameof(Index));
            }
            ViewData["SexCode"] = new SelectList(_context.Sex, "SexCode", "SexName", Nz.SexCode);
            return View(Nz);
        }

the partial view 'EditNz' in Mkh controller:

@model IEnumerable<Mkh><h4>MkhTbl</h4><hr /><table class="table"><thead><tr><th>
                    Date</th><th>
                    Days</th><th>
                    Notes</th><th>
                    Mkh Type</th><th></th></tr></thead><tbody>
            @foreach (var item in Model)
            {<tr><td> 
                        @Html.EditorFor(modelItem => item.MkhDate)</td><td>
                        @Html.EditorFor(modelItem => item.Days)</td><td>
                        @Html.EditorFor(modelItem => item.Notes)</td><td>
                        @Html.EditorFor(modelItem => item.MkhCodeNavigation.MkhName)</td></tr>
            }</tbody></table>

    @section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }

and the calling of the previous partial in Edit view in NzController:

@{ await Html.RenderPartialAsync("~/Views/Mkh/EditNz.cshtml", Model.Mkh); }

Now when I press save button (submit) no data is saved for the partial one like days! Why? and How to solve please?

and How to return Select with returned values from MkhType? (using MkhCodeNavigation I think)

How to get scanned image via Twain driver in a .net core project

$
0
0

Hi all,

I need a piece of code which is able to get an image (preferably pdf) from a scanner. Do you have any?

Thanks


.net core create word document create and download

$
0
0

I have Project Of .net Core and i need to create a custom word document.

Like: simple "Hello Word!!"

Thanks In Advance.

Error while deploying Core App on Debian/Linux

$
0
0

I am trying to upgrade a previously installed/running Asp.net core (self contained) application on a Debian vm. After I copy the new dlls and test with dotnet path-to-my-app.dll I get this error, which I have no idea about.

LTTng-UST: Error (-17) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.

I am probably doing something wrong, either in deployment or configuration but can't really pin-point it. There is hardly anything available on this so  any help is highly appreciated.

Connecting to a third-party SOAP service with .NET Core 2.0 behind a proxy

$
0
0

Trying to connect to a third-party SOAP web service with .NET Core 2.0 behind a proxy. With .NET Core 2.x I have the only option to create a WCF Web Service as a Connected service, however the Proxy objects generated are not same as with full frame .NET Web Service Reference. The class properties are missing in .NET Core (WCF Web Service as Connected service) Proxy, and it creates only async methods (which I don't mind).

With .NET Core 2.x I am getting an exception: ServiceModel.CommunicationException: Unrecognized message version when I call a method on the proxy client after setting basic authentication credentials from code

Everything works fine with basic authentication from a full frame .NET console program (VS 2017) after creating a Web Service Reference. My company has moved to .net core and this is a problem we need a solution

Login Form Partial View in ASP.NET Core 2.2 Razor Pages

How to get text of label from database dynamically vertically ?

$
0
0

Problem

How to get text of label from database dynamically  vertically ?

so that when user or change text no need to change any thing on interface or ui code for label

so that i get text from reference file and it working good but i need to make it work vertically as

a

b

c

not a b c

so that what i try to do is 

public  class GetReferenceViewComponent : ViewComponent
    {
        private readonly TabDbContext _context;

        public GetReferenceViewComponent(TabDbContext context)
        {
            _context = context;
        }

        public async Task<IViewComponentResult> InvokeAsync(string TableName)
        {
            var result = _context.ReferenceFiles.Where(r => r.TableName == TableName).ToList();
            ViewBag.GetReference = result;
            return View();
        }
    }
and under shared/Components/GetReference/Default.cshtml
I put following code to get text based on fieldname of reference file table
@foreach (var itemes in ViewBag.GetReference)
{<thead>
        @itemes.FieldName</thead>

and on index view I call as following :

 @await Component.InvokeAsync("GetReference", new { TableName = "Employees" }) }
SampleData 

Code TableName FieldName 

1    Employees EmployeeId 
2    Employees BranchCode 



code above work on default index view good
but when i go to create page i need it vertically it not work
as
EmployeeId textboxinput
BranchCode textboxinput
<div class="row"><div class="col-md-4"><form asp-action="Create"><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="EmployeeId" class="control-label"></label><input asp-for="EmployeeId" class="form-control" /><span asp-validation-for="EmployeeId" class="text-danger"></span></div><div class="form-group"><label asp-for="BranchCode" class="control-label"></label><input asp-for="BranchCode" class="form-control" /><span asp-validation-for="BranchCode" class="text-danger"></span></div></div></div>
 public class ReferenceFile
 {
 public int Code { get; set; }
 public string TableName { get; set; }
 public string FieldName { get; set; }

 }


second page not reached on IIS

$
0
0

On IIS Express my application calls from a table like this 

<td><a href="/PageX?nata=@Html.DisplayFor(modelItem => item.theKey)" class="btn btn-info"   

and so forth ....

But when I published to the virtual machine the app & first page index runs fine but the next page does not HTTP error 500.0  I noticed the IIS page acts as if the requested URL is htttp://localhost:80/PageX?nata=2111 and Physical Path C:\innetpub\wwwroot\PageX   That physical path doesn't exist & the diagnostic may not be relevent

The event log looks fine   I even put an email to send me if the OnGet() fired on 'PageX' - but nothing happens at published    I cannot think this is unique....

ExecuteRequestHandler,  AspNetCoreModuleV2, aspNetCore, 0x80004005   and the link doesn't make sense ...to me.  https://support.microsoft.com/en-us/help/942031/http-error-500-0-internal-server-error-error-when-you-you-open-an-iis

Thanks !!!

data-bind is successful but the actual value is not being displayed

$
0
0

public enum OwnershipType
{
Buying,
Owns,
Renting,
[AS400Value("Other")]
Boards,
[Display(Name = "Live with Relative"), AS400Value("Other")]
LiveWithRelative,
Other
}

EDIT sscreen where I select the value in teh dropdown

<div class="form-group">
<label asp-for="OwnershipType" style="float:left;margin-right:5px;"></label>
<div class="input-group col-md-6">

<select class="form-control" asp-for="OwnershipType"
asp-items="@Html.GetEnumSelectList<Ucfs.LoanPortal.Data.Entities.OwnershipType>
()" data-bind="value :ownershipType">
<option>Select</option>
</select>
<span asp-validation-for="OwnershipType"></span>
</div>
</div>

THIS IS THE DISPLAY CODE : AND RIGHT NOW IF I SELECT BUYING : IT RETURNS 0 INSTEAD OF "BUYING" 

<div class="col-md-6">
<div class="form-row">
<label class="col-md-5 col-form-label" asp-for="OwnershipType">Type Of Housing</label>
<div class="col-md">
<span class="form-control-plaintext" data-bind="text: ownershipType"></span>
</div>
</div>
</div>

PLEASE HELP ME 


How to check for null and empty?

$
0
0

I'm wondering what is the right way to check for null or empty entries in controllers in asp.net core and c# in general.

There are so many instances where I have to check this for various scenarios:

From database calls: 
When I use entityframework core, I often use FirstOrDefault() when querying a table. This returns a default value if none is found. but what is this value and how do I check if this default value is returned? 

var person = await _context.Persons.FirstOrDefaultAsync(i => i.ID == id);
if(person is null)
...
if(person == null)

How about if I return a collection? It can be null or it can just be empty

var persons = _context.Person.ToList();
if(persons.Any())
...
if(persons is null)
...
if(persons == null)
//you can probably also use Count() too

Then you have strings:

//model.Name is a string returned from frontend
if(string.IsNullOrWhiteSpace(model.Name))
...
if(model.Name is null)
if(model.Name == null)

I see no consistency on this when I read other code and I have really not much clue myself. But I want to find out what is the best way to check for each scenario. I would imagine there are articles on this? 

Verify Code For Forgot Password in Asp.net Core

$
0
0

Hi,

in asp.net core when user click reset password ,send email to him for reset password page but
i want when user click i want send code to phone then verify it and redirect to Reset Password View for reset his password?
but in Account Controller how to generate code and then verify it for reset  his password?
how to use send code to phone instead of email ?

Difficulty in running Asp.net core web app in solution that previously contained asp.net apps

$
0
0

Dear All,

I have a solution that contains loasd of my asp.net project as a matter of fact I started building this solution with VS2013 before asp.net core came out. But since I have vs 2017. I copied the solution to the VS 2017 project folder. Right now I would to start a new project which suppose to be a asp.net core web application. But I usually have difficulties adding .net core project to this solution. I have added one and I can not run the web application. each time I try IIS just tends to freeze. I ended up with this message below

<div class="content-container">

HTTP Error 502.3 - Bad Gateway

The specified CGI application encountered an error and the server terminated the process.

</div> <div class="content-container">

Most likely causes:

  • The CGI application did not return a valid set of HTTP errors.
  • A server acting as a proxy or gateway was unable to process the request due to an error in a parent gateway.
</div> <div class="content-container">

Things you can try:

  • Use DebugDiag to troubleshoot the CGI application.
  • Determine if a proxy or gateway is responsible for this error.
</div> <div class="content-container">

Detailed Error Information:

<div id="details-left">
Module   AspNetCoreModule
Notification   ExecuteRequestHandler
Handler   aspNetCore
Error Code   0x80072ee2
</div> <div id="details-right"></div> <div>Please what do I do to ensure that I can have my asp.net core project within this solution.   Please  I would appreciate swift response cos the client is already on my case.</div> <div></div> <div>Thanks alot.</div>
</div>

Insert Full Html into Razor Page or ?

$
0
0

One of my  razor pages has a full blown HTML page for a model variable

<div><pre>@Model.TheHMLText</pre></div>   -  HTMLText comes with its own head and style content....  so that just gets rendered with all the HTML tags as in 

<head>
<title></title>
<style type="text/css">  etc etc

I'm looking at @Html.RenderPartial(...)    But this function feels like it looks  static content - but mine is dynamically loaded from my model.  So....  What are my options... ??

Thanks !!!

Allow writing elements inside a custom tag helper

$
0
0

Hello!

I'd like to know if it is possible to write a custom tag helper such as:

<preparation>
    <h3>I need to put elements here!</h3>
</preparation>

To get rendered into:

<div class="row">
    <div class="col">

        <h3>I need to put elements here!</h3>

    </div>
</div>


So far I began writing the tag helper class code for it, but I didn't manage to add child items into it:

public class PreparationTagHelper : TagHelper {
    public override void Process(TagHelperContext context, TagHelperOutput output) {
        output.TagName = "div";
        output.TagMode = TagMode.StartTagAndEndTag;
        output.Attributes.Add("class", "row");

        //I wish I could do this:
        //output.Children.Add("div").Attributes.Add("class");
    }
}

Can you help me? Thanks!

Viewing all 9386 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>