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

Hosting ASP.net Core MVC on Raspberry Pi 3b+ Acces denied

$
0
0

Hello people

I am programming in ASP.net normally for MVC but I am making some website for school project and I thaught maybe it is nice when I can run it on a Raspberry Pi. So after searching on the web I made my ASP.net MVC website to a ASP.net Core MVC website and I deployed that to my raspberry pi. That worked but now I updated my code and I want to redeployed it and I have some strange error. 

Have any of you haved that error already?


GridView in .Net Core (with razor)

$
0
0

Hi,

I am totally new at Core and Razor pages, I have searched for samples to fill a html table (since Gridview is no longer available) but all I see is MVC and I need Razor.

Can somebody help me with a basic example of code?, I have my own connection, so I don't use EF.

Thanks in advance.

Mixed Authentication

$
0
0

Hi all,

I hoping someone can give me some advice on the best way to proceed there are lots of solutions to this I have seen but none seems to fit my needs.

So I am creating a MVC application in .NET Core 3.1 which also has an Angular SPA. I will be deploying to IIS 7.5. 

The idea is for the MVC application to provide REST API's to the SPA, and i need to authorise with windows authentication so it can access server resources such as msmdpmup (Analysis Services) however not all domain users have access to this. I cannot use roles because the roles are based around departments for my company so I would like to also perform a check to a database to see if the user has access.

I have already tried using cookie authentication but instead of storing username and passwords I validate the credentials against the active directory and also perform a check against the database which gives access to the correct users but does not allow for passthrough authentication to msmdpump as the header does not contain a windows auth token.

Would anyone have any advice on how I should approach this?

If you need anymore detail please let me know.

Cheers,Joe

Sorting MVC View Results (really more of an architectural issue)

$
0
0

My controller has an [HttpGet] index() action that displays a form with several inputs that are not bound to my database.  For example there is a drop-down containing all the years from 1960 to 2020.  When a user selects one, the form is posted and the [HttpPost] action method finds every item in the database from that year.  Works great!

I would like a user to be able to sort the results by item name.  I would also eventually like to do pagination.

1.  Is there a Javascript/CSS library that will do all this so I can just plug it in?

2.  If not, I have attempted to code it.  However I can't get the data to persist when I do something like this:

<a asp-action="Index" asp-route-sortorder="@ViewBag.NameSortParm">Sort by Airline / Bag Name</a>

in order to trigger this

            switch (sortorder)
            {
                case "airline_desc":
                    baglist = baglist.OrderByDescending(s => s.Airline).ToList();
                    break;
                case "year":
                    baglist = baglist.OrderBy(s => s.Year).ToList();
                    break;
                case "year_desc":
                    baglist = baglist.OrderByDescending(s => s.Year).ToList();
                    break;
                default:
                    baglist = baglist.OrderBy(s => s.Airline).ToList();
                    break;
            }

which calls the Index() get method, meaning I've lost the filtered data from the model.  It no longer has any idea that the data from the dropdown was say, 2005.  I'm guessing that the original form shouldn't post and should instead use a querystring.  is that a better way to go?  Even so, it still doesn't help me retain only the 2005 data when sorting.

I suppose I could cache the results (now that I know how to do so) but it seems like there's a better, clearer way to do so.

Second login form in one solution

$
0
0

I start use ASP.Net Identity in my app. I have one page (/identity/account/login) where i can type login and password and login to page. But i want create second login page in home page. In home page i have button who create pop-up where i would like create second login form. It is posible?

First login form (deafult):

Second login form (as pop-up in home page):

What I have tried:

In home page i try something like this, but it doesn't work

<partial name="~/Areas/Identity/Pages/Account/Login.cshtml" model="@LoginModel" view-data="ViewData" />

Whats more if click button in popup i create function:

$("#login").click(function () {
        Login();
         });


          function Login() {
              var InputLogin = $('#email').val();
              var InputPassword = $('#password').val();$.ajax({
            type: "POST",
            url: 'Identity/Pages/Login/OnPostAsync',
            data: { "Input.Login": InputLogin, "Input.Email": InputLogin },

            dataType: "json",
            success: function () { alert('Ok'); },
            error: function () { alert('Don't ok'); },
        });
        }

Modal popup and pass value

$
0
0

Hi,

I am starting with Razor Pages, I have a table and each record has a "details" button, so I need to show a modal popup with the details, I used to do this in asp.net with Ajaxtoolkit ModalPopupExtender, but now I have no idea.

I have tried this sample https://softdevpractice.com/blog/razor-pages-ajax-modals-with-validation/ but no luck, I just can't make it work.

Any ideas? any tiny sample?

(Please, not MVC, that will confuse me even more)

Thanks in advance :)

How to add google Analytics to my core 2.1 web app locally?

$
0
0

Hi

I'm totally new at Google Analytics.

I want to add google Analytics to my core 2.1 web app. to show analytics on localhost, So I created a google analytics account.

And created Admin account and property like this:

Also created data streams like this:

Then I copied gtag.js code and paste it at <head> tag of my shared _Layout view.

Is there any steps missed? how to know if this is working? and how to open the google analytics results from the web application itself (localhost of course)?

ASP.NET Core - XML

$
0
0

Hi,

I need your help again.

Last week I published a thread because I couldn't read the XML.

This I have already managed to do.

But now I have another problem. When I try to read the file it gives this error.(link bellow)

Error

I will put some code lines.

XML:

-<products>


-<product><id>100</id><name>Ball</name><price>15</price><quantity>2</quantity>


-<description><comment>aaa</comment></description></product></products>

MODEL:

 [Table("Table")]
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Price { get; set; }
        public int Quantity { get; set; }

        public Description Description{ get; set; }
        
    }
   
   public class Description
    {
        [Key]
        public string DescriptionComment { get; set; }
    }

CONTROLLER:

  private List<Product> ProcessImport(string path)
        {
            XDocument xDocument = XDocument.Load(path);
            List<Product> products = xDocument.Descendants("product").Select
                (p => new Product()
                {
                   Id = Convert.ToInt32(p.Element("id").Value),
                   Name=p.Element("name").Value,
                   Quantity = Convert.ToInt32(p.Element("quantity").Value),
                   Price = Convert.ToInt32(p.Element("price").Value),
                   Description = new Description()
                   {
                       DescriptionComment= p.Element("description").Element("comment").Value
                   }
                }).ToList();
            foreach(var product in products)
            {
                var productInfo = db.Products.SingleOrDefault(p => p.Id.Equals(product.Id));
                if (productInfo != null)
                {
                    productInfo.Id = product.Id;
                    productInfo.Name = product.Name;
                    productInfo.Quantity = product.Quantity;
                    productInfo.Price = product.Price;
(I think the problem is here!) } else { db.Products.Add(product); } db.SaveChanges(); } return products; }

If you can help me I woul appreciate.

Thanks!

Best regards

Andre


Showing links based on user access to groups in AAD

$
0
0

Hi, 

I am currently developing a website to enable my theatre group to be able to do things remotely but i am having some difficulties. 

  1. I am unable to show links based on the access to groups in the AAD. here is the code i have. it just doesn't work.
  2. I also have had an issue when i have logged in that im getting the error "You do not have permission to view this directory or page." - https://tmtg.azurewebsites.net/signin-oidc

Home Controller

namespace TMTGWeb.Controllers
{
    public class HomeController : Controller
    {
        [AllowAnonymous]
        public IActionResult Index()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Privacy()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult About()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Book()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Contact()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Events()
        {
            return View();
        }

        [Authorize("ActiveMembers")]
        public IActionResult Members()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Join()
        {
            return View();
        }
        [AllowAnonymous]
        public IActionResult Pleaseconfirm()
        {
            return View();
        }




        
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}

Layout

@using Microsoft.AspNetCore.Authorization
@inject IAuthorizationService _authorizationService<!DOCTYPE html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>@ViewBag.Title</title><environment include="Development"><link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /><link href="~/css/fonts.css" rel="stylesheet" /><link href="~/css/sb-admin.css" rel="stylesheet" /><link href="~/css/font-awesome.css" rel="stylesheet" /><link rel="stylesheet" href="~/css/site.css" /><link href="~/css/datatables.min.css" rel="stylesheet" /></environment><environment exclude="Development"><link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /><link href="~/css/fonts.css" rel="stylesheet" /><link href="~/css/sb-admin.css" rel="stylesheet" /><link href="~/css/font-awesome.css" rel="stylesheet" /><link rel="stylesheet" href="~/css/site.css" /><link href="~/css/datatables.min.css" rel="stylesheet" /></environment><environment include="Development"><script src="~/lib/jquery/dist/jquery.js"></script><script src="~/lib/bootstrap/dist/js/bootstrap.js"></script><script src="~/js/site.js" asp-append-version="true"></script><script src="~/js/datatables.min.js"></script></environment><environment exclude="Development"><script src="~/lib/jquery/dist/jquery.js"></script><script src="~/lib/bootstrap/dist/js/bootstrap.js"></script><script src="~/js/site.js" asp-append-version="true"></script><script src="~/js/datatables.min.js"></script></environment></head><body><nav class="navbar navbar-expand-lg navbar-dark bg-dark"><a class="navbar-brand" href="#">TMTG</a><button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbarSupportedContent"><ul class="navbar-nav mr-auto"><li>@Html.ActionLink("Home", "Index", "Home", "", new { @class = "nav-link" })</li><li>@Html.ActionLink("About", "About", "Home", "", new { @class = "nav-link" })</li><li>@Html.ActionLink("Contact", "Contact", "Home", "", new { @class = "nav-link" })</li>
                @if ((await _authorizationService.AuthorizeAsync(User, "ActiveMembers")).Succeeded)
                {<li> @Html.ActionLink("Members", "Members", "Home", "", new { @class = "nav-link" }) </li>
                }
                @if ((await _authorizationService.AuthorizeAsync(User, "Committee")).Succeeded)
                {<li> @Html.ActionLink("Committee", "Members", "Home", "", new { @class = "nav-link" }) </li>
                }
                @if ((await _authorizationService.AuthorizeAsync(User, "Ticketing")).Succeeded)
                {<li> @Html.ActionLink("Ticketing", "Members", "Home", "", new { @class = "nav-link" }) </li>
                }
                @if ((await _authorizationService.AuthorizeAsync(User, "ProductionTeam")).Succeeded)
                {<li> @Html.ActionLink("ProductionTeam", "Members", "Home", "", new { @class = "nav-link" }) </li>
                }
                @if ((await _authorizationService.AuthorizeAsync(User, "Musicians")).Succeeded)
                {<li> @Html.ActionLink("Musicians", "Members", "Home", "", new { @class = "nav-link" }) </li>
                }</ul></div></body></html>

Startup

namespace TMTGWeb
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));
            services.AddAuthorization(options =>
            {
                options.AddPolicy("ActiveMembers", p =>

                {
                    p.RequireClaim("groups", "e8c32cc7-61e0-46b1-b896-7290d7e80ca1");
                });

                options.AddPolicy("Committee", p =>

                {
                    p.RequireClaim("groups", "6acf99d7-9411-45e9-95d0-84bcfa47b496");
                });

                options.AddPolicy("OffStageMembers", p =>

                {
                    p.RequireClaim("groups", "74bd0371-2951-4c0b-8d1d-ca2bc9fe13e4");
                });

                options.AddPolicy("Ticketing", p =>

                {
                    p.RequireClaim("groups", "de2dece0-6291-41cf-bd08-5b5e08faafc4");
                });

                options.AddPolicy("ProductionTeam", p =>

                {
                    p.RequireClaim("groups", "97a792a9-d3dc-48bd-b386-8a3a8fe99a19");
                });

                options.AddPolicy("TechnicalAdmin", p =>

                {
                    p.RequireClaim("groups", "efd5f835-e0bc-4324-90b1-82f95f0c0a89");
                });

                options.AddPolicy("Musicians", p =>

                {
                    p.RequireClaim("groups", "694fcfaa-ad22-494a-900b-2c7695b8d193");
                });

            });
            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}
{"AzureAd": {"Instance": "https://login.microsoftonline.com/","Domain": "https://tmtg.azurewebsites.net","TenantId": "MY TENANT ID IS CORRECT","ClientId": "MY CLIENT ID IS CORRECT","CallbackPath": "/signin-oidc"
  },"Logging": {"LogLevel": {"Default": "Warning"
    }
  },"AllowedHosts": "*"
}

any help would be appriciated.

unit test migration from asp.net to asp.net core

$
0
0

HI,


I migrated unit test and getting error method is inaccessible due to its protection level c#

method is internal and in unit test project i have added reference this behaviour is working in asp.net project but not working when i migrated UT to asp.net core platefom

please suggest

Javascript and Asp.Net Core 3.1 input check boxes broken

$
0
0

Hello,

     So I had this working in Asp.net Core 2.2 with Twitter-Bootstrap 3.3.7.  I then upgraded to Asp.net Core 3.1 and Twitter-Bootstrap 4.4.  Now I am unable to get some of my javascript functions to work.  Setting breakpoints in the javascript in Chrome and Edge, they do not get hit at all.  Though I ran the output from the web through JS Fiddle and it works perfectly fine there.  So I am at a loss for what I did to break this.

What I have is a gating function within javascript that will uncheck any check boxes that are in sequence after a check box if it is unchecked, if it is checked it will enable the next available check box, leaving the others disabled.  When I run it in IIS Express this no longer happens.

Here is the Javascript I have for one page:

//Loops through the checkboxes and disables the next ones if the previous is not checked
function changeFields(fields) {
    fields.change(function () {
        Array.prototype.reduce.call(fields, function (prev, curr) {
            curr.disabled = !prev.checked || prev.disabled;


            //If you want to uncheck remaining use this instead of above line:
            curr.checked = prev.checked ? curr.checked : false;
            curr.disabled = !prev.checked;

            return curr;
        });
    });
}

//Call the for the CharacterCraft
changeFields($(".cALScb"));
changeFields($(".cALMcb"));
changeFields($(".cBLScb"));
changeFields($(".cBLMcb"));
changeFields($(".cCLScb"));
changeFields($(".cCLMcb"));



Here is the what I have in view calling this:

<form asp-controller="CharacterCrafts" asp-action="Edit" method="post"><div class="form-horizontal"><hr />
        @Html.ValidationSummary( true, "", new { @class = "text-danger" } )<div class="col-lg-12 text-center"><b style="text-align: center; font-family: 'Times New Roman', Times, serif; font-size: x-large">@Html.DisplayFor( a => a.CharNames.CharFullName )</b><br /><b style="text-align: center; font-family: 'Times New Roman', Times, serif; font-size: large">@Html.DisplayFor( a => a.CharNames.ProfName )</b></div><br /><br /><div class="form-group"><div class="form-group row"><div class="col-lg-2">
                    @Html.Label( "Crafting Class" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div></div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListA[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListA.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListA[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListA[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListA[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListA[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListA[i].CraftLevelSet" class="cALScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListA[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListA[i].CraftLevelMastery" class="cALMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListB[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListB.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListB[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListB[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListB[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListB[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListB[i].CraftLevelSet" class="cBLScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListB[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListB[i].CraftLevelMastery" class="cBLMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListC[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListC.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListC[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListC[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListC[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListC[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListC[i].CraftLevelSet" class="cCLScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListC[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListC[i].CraftLevelMastery" class="cCLMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div></div><div class="form-group row"><div class="col-lg-12 row"><div class="col-lg-3"><b>Select a Guild:</b></div>
                @for ( var i = 0; i<Model.Guild.Count; i++ )
                {<input type="hidden" asp-for="@Model.Guild[i].FactionID" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.Guild[i].isChecked" /></div><div class="col-lg-3"><b>@Html.DisplayFor( a => a.Guild[ i ].FactionName )</b></div>
                }</div></div><div class="form-group row"><div class="col-lg-12 row"><div class="col-lg-offset-2 col-lg-2"><input type="submit" value="Save" class="btn btn-secondary" /></div><div class="col-lg-5"></div><div class="col-lg-2"><a asp-controller="Menu" , asp-action="EdChar" , null, class="btn btn-danger">Cancel</a></div></div></div></div></form>

Everything displays correctly on the page, but after an unchecked check box everything is still enabled.  This can been seen in the output from Edge:

<div class="form-group"><div class="form-group row"><div class="col-lg-2"><label for="Crafting_Class">Crafting Class</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Farmer</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_0__CharCraftCharID" name="CraftListA[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_0__CharCraftClassID" name="CraftListA[0].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_0__CharCraftLevelID" name="CraftListA[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_0__CraftLevelTier" name="CraftListA[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_0__CraftLevelSet" name="CraftListA[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_0__CraftLevelMastery" name="CraftListA[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_1__CharCraftCharID" name="CraftListA[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_1__CharCraftClassID" name="CraftListA[1].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_1__CharCraftLevelID" name="CraftListA[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_1__CraftLevelTier" name="CraftListA[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_1__CraftLevelSet" name="CraftListA[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_1__CraftLevelMastery" name="CraftListA[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_2__CharCraftCharID" name="CraftListA[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_2__CharCraftClassID" name="CraftListA[2].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_2__CharCraftLevelID" name="CraftListA[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_2__CraftLevelTier" name="CraftListA[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_2__CraftLevelSet" name="CraftListA[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_2__CraftLevelMastery" name="CraftListA[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_3__CharCraftCharID" name="CraftListA[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_3__CharCraftClassID" name="CraftListA[3].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_3__CharCraftLevelID" name="CraftListA[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_3__CraftLevelTier" name="CraftListA[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_3__CraftLevelSet" name="CraftListA[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_3__CraftLevelMastery" name="CraftListA[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_4__CharCraftCharID" name="CraftListA[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_4__CharCraftClassID" name="CraftListA[4].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_4__CharCraftLevelID" name="CraftListA[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_4__CraftLevelTier" name="CraftListA[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_4__CraftLevelSet" name="CraftListA[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_4__CraftLevelMastery" name="CraftListA[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_5__CharCraftCharID" name="CraftListA[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_5__CharCraftClassID" name="CraftListA[5].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_5__CharCraftLevelID" name="CraftListA[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_5__CraftLevelTier" name="CraftListA[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_5__CraftLevelSet" name="CraftListA[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_5__CraftLevelMastery" name="CraftListA[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_6__CharCraftCharID" name="CraftListA[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_6__CharCraftClassID" name="CraftListA[6].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_6__CharCraftLevelID" name="CraftListA[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_6__CraftLevelTier" name="CraftListA[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_6__CraftLevelSet" name="CraftListA[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_6__CraftLevelMastery" name="CraftListA[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_7__CharCraftCharID" name="CraftListA[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_7__CharCraftClassID" name="CraftListA[7].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_7__CharCraftLevelID" name="CraftListA[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_7__CraftLevelTier" name="CraftListA[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_7__CraftLevelSet" name="CraftListA[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_7__CraftLevelMastery" name="CraftListA[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_8__CharCraftCharID" name="CraftListA[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_8__CharCraftClassID" name="CraftListA[8].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_8__CharCraftLevelID" name="CraftListA[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_8__CraftLevelTier" name="CraftListA[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_8__CraftLevelSet" name="CraftListA[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_8__CraftLevelMastery" name="CraftListA[8].CraftLevelMastery" value="true"></div><br></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Scholar</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_0__CharCraftCharID" name="CraftListB[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_0__CharCraftClassID" name="CraftListB[0].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_0__CharCraftLevelID" name="CraftListB[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_0__CraftLevelTier" name="CraftListB[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_0__CraftLevelSet" name="CraftListB[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_0__CraftLevelMastery" name="CraftListB[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_1__CharCraftCharID" name="CraftListB[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_1__CharCraftClassID" name="CraftListB[1].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_1__CharCraftLevelID" name="CraftListB[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_1__CraftLevelTier" name="CraftListB[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_1__CraftLevelSet" name="CraftListB[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_1__CraftLevelMastery" name="CraftListB[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_2__CharCraftCharID" name="CraftListB[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_2__CharCraftClassID" name="CraftListB[2].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_2__CharCraftLevelID" name="CraftListB[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_2__CraftLevelTier" name="CraftListB[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_2__CraftLevelSet" name="CraftListB[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_2__CraftLevelMastery" name="CraftListB[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_3__CharCraftCharID" name="CraftListB[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_3__CharCraftClassID" name="CraftListB[3].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_3__CharCraftLevelID" name="CraftListB[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_3__CraftLevelTier" name="CraftListB[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_3__CraftLevelSet" name="CraftListB[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_3__CraftLevelMastery" name="CraftListB[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_4__CharCraftCharID" name="CraftListB[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_4__CharCraftClassID" name="CraftListB[4].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_4__CharCraftLevelID" name="CraftListB[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_4__CraftLevelTier" name="CraftListB[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_4__CraftLevelSet" name="CraftListB[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_4__CraftLevelMastery" name="CraftListB[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_5__CharCraftCharID" name="CraftListB[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_5__CharCraftClassID" name="CraftListB[5].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_5__CharCraftLevelID" name="CraftListB[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_5__CraftLevelTier" name="CraftListB[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_5__CraftLevelSet" name="CraftListB[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_5__CraftLevelMastery" name="CraftListB[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_6__CharCraftCharID" name="CraftListB[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_6__CharCraftClassID" name="CraftListB[6].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_6__CharCraftLevelID" name="CraftListB[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_6__CraftLevelTier" name="CraftListB[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_6__CraftLevelSet" name="CraftListB[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_6__CraftLevelMastery" name="CraftListB[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_7__CharCraftCharID" name="CraftListB[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_7__CharCraftClassID" name="CraftListB[7].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_7__CharCraftLevelID" name="CraftListB[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_7__CraftLevelTier" name="CraftListB[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_7__CraftLevelSet" name="CraftListB[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_7__CraftLevelMastery" name="CraftListB[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_8__CharCraftCharID" name="CraftListB[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_8__CharCraftClassID" name="CraftListB[8].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_8__CharCraftLevelID" name="CraftListB[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_8__CraftLevelTier" name="CraftListB[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_8__CraftLevelSet" name="CraftListB[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_8__CraftLevelMastery" name="CraftListB[8].CraftLevelMastery" value="true"></div><br></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Weaponsmith</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_0__CharCraftCharID" name="CraftListC[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_0__CharCraftClassID" name="CraftListC[0].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_0__CharCraftLevelID" name="CraftListC[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_0__CraftLevelTier" name="CraftListC[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_0__CraftLevelSet" name="CraftListC[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_0__CraftLevelMastery" name="CraftListC[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_1__CharCraftCharID" name="CraftListC[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_1__CharCraftClassID" name="CraftListC[1].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_1__CharCraftLevelID" name="CraftListC[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_1__CraftLevelTier" name="CraftListC[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_1__CraftLevelSet" name="CraftListC[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_1__CraftLevelMastery" name="CraftListC[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_2__CharCraftCharID" name="CraftListC[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_2__CharCraftClassID" name="CraftListC[2].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_2__CharCraftLevelID" name="CraftListC[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_2__CraftLevelTier" name="CraftListC[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_2__CraftLevelSet" name="CraftListC[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_2__CraftLevelMastery" name="CraftListC[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_3__CharCraftCharID" name="CraftListC[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_3__CharCraftClassID" name="CraftListC[3].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_3__CharCraftLevelID" name="CraftListC[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_3__CraftLevelTier" name="CraftListC[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_3__CraftLevelSet" name="CraftListC[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_3__CraftLevelMastery" name="CraftListC[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_4__CharCraftCharID" name="CraftListC[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_4__CharCraftClassID" name="CraftListC[4].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_4__CharCraftLevelID" name="CraftListC[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_4__CraftLevelTier" name="CraftListC[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_4__CraftLevelSet" name="CraftListC[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_4__CraftLevelMastery" name="CraftListC[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_5__CharCraftCharID" name="CraftListC[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_5__CharCraftClassID" name="CraftListC[5].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_5__CharCraftLevelID" name="CraftListC[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_5__CraftLevelTier" name="CraftListC[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_5__CraftLevelSet" name="CraftListC[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_5__CraftLevelMastery" name="CraftListC[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_6__CharCraftCharID" name="CraftListC[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_6__CharCraftClassID" name="CraftListC[6].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_6__CharCraftLevelID" name="CraftListC[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_6__CraftLevelTier" name="CraftListC[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_6__CraftLevelSet" name="CraftListC[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_6__CraftLevelMastery" name="CraftListC[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_7__CharCraftCharID" name="CraftListC[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_7__CharCraftClassID" name="CraftListC[7].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_7__CharCraftLevelID" name="CraftListC[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_7__CraftLevelTier" name="CraftListC[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_7__CraftLevelSet" name="CraftListC[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_7__CraftLevelMastery" name="CraftListC[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_8__CharCraftCharID" name="CraftListC[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_8__CharCraftClassID" name="CraftListC[8].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_8__CharCraftLevelID" name="CraftListC[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_8__CraftLevelTier" name="CraftListC[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cCLScb" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_8__CraftLevelSet" name="CraftListC[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_8__CraftLevelMastery" name="CraftListC[8].CraftLevelMastery" value="true"></div><br></div></div></div>

Ideally from the output the very last check box should be disabled, but it is not.  Though if I go to JS Fiddle, this works as such: https://jsfiddle.net/MikeRM2/bzfcme06/

So this leads to wondering what went wrong, as it works in JS Fiddle but not on the actual site.  I am not getting any errors in the console or debug.  Any thoughts on why this is not working anymore would be appreciated.

Returning a mp3 file trough File Action results, stops after being played for 10 minutes

$
0
0

I have an action that returns mp3 file as below : 

                var memory = new MemoryStream();
                using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await stream.CopyToAsync(memory);
                }
                memory.Position = 0;

                //Response.Headers.Add("Accept-Ranges", "bytes");
                //Response.Headers.Add("Connection", "keep-alive");

                return File(memory, "audio/mpeg", $"music.mp3", true);

So the is partial content. After 10 minutes of playing the mp3 file by calling my action, the player stops. I saw that html default player has logged following error in the browser console :

" net::ERR_CONNECTION_RESET 206 (Partial Content)"

What would be the reason ? 

How to resize image before upload to varbinary column?

$
0
0

Hi

I'm uploading an image to a varbinary column in the database successfully. But I want to resize it before uploading.

So this is what I tried:

Guests model:

public byte[] Image { get; set; }

public string ContentType { get; set; }

ImageExtentions Class to resize the image:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace System.Drawing
{
    public static class ImageExtentions
    {
        public static Image Resize(this Image current, int maxWidth, int maxHeight)
        {
            int width, height;

            if (current.Width > current.Height)
            {
                width = maxWidth;
                height = Convert.ToInt32(current.Height * maxHeight / (double)current.Width);
            }
            else
            {
                width = Convert.ToInt32(current.Width * maxWidth / (double)current.Height);
                height = maxHeight;
            }

            var canvas = new Bitmap(width, height);

            using (var graphics = Graphics.FromImage(canvas))
            {
                graphics.CompositingQuality = CompositingQuality.HighSpeed;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.DrawImage(current, 0, 0, width, height);
            }

            return canvas;
        }

        public static byte[] ToByteArray(this Image current)
        {
            using (var stream = new MemoryStream())
            {
                current.Save(stream, current.RawFormat);
                return stream.ToArray();
            }
        }
    }
}

GuestsController:

//using a lot
using System.Drawing;
namespace Proj.Controllers
{
public class GuestsController : Controller
{
private readonly ApplicationDbContext _context; public GuestsController(ApplicationDbContext context) { _context = context; } //Some code [HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Create([Bind("Id,Name,DoB")] Guests guest, List<IFormFile> Image) { IFormFile uploadedImage = Image.FirstOrDefault(); if (ModelState.IsValid) { foreach (var item in Image) { if (item.Length > 0) { using (var stream = new MemoryStream()) { using (Image img = Image.FromStream(uploadedImage.OpenReadStream())) { Stream ms = new MemoryStream(img.Resize(900, 1000).ToByteArray()); FileStreamResult fsr = new FileStreamResult(ms, "image/jpg"); uploadedImage.OpenReadStream().CopyTo(stream); guest.Image = stream.ToArray(); guest.ContentType = uploadedImage.ContentType; } } } } } _context.Add(guest); await _context.SaveChangesAsync();
}

But this scenario gives me this error:

List<IFormFile> does not contain a definition for 'FromStream' and no accessible extension method  'FromStream' accepting a first argument of type List<IFormFile> could be found.

How to perform this task please?

Value passed by session from method to another does not work!

$
0
0

Hi

I have tow query type models that I want to get their data by ajax in one view with Entity Framework Core.

I'm trying to pass the number of records returned by Ajax to the caller view by session, But no value returned.

HolidaysHeader model:

    public class HolidaysHeader 
    {
        public int Id { get; set; }

        public string Name{ get; set; }
    }

ActionsHeader model:

    public class ActionsHeader
    {
        public int Id { get; set; }

        public string Name{ get; set; }
    }

ApplicationDBContext:

public virtual DbQuery<ActionsHeader> ActionsHeader { get; set; }
public virtual DbQuery<HolidaysHeader > HolidaysHeader { get; set; }

Actions get data method:

        public async Task<List<ActionsHeader>> ActionsHeaderE(decimal? sid)
        {
            var nContext = _context.Query<ActionsHeader>().AsQueryable();

            if (sid != null || sid.GetValueOrDefault() != 0)
            {
                nContext = nContext .Where(s => s.Id.ToString().Contains(sid.ToString()));
            }

            nContext = nContext.OrderByDescending(s => s.Id).Take(1000);
            var data = await nContext.ToListAsync();HttpContext.Session.SetString("A", data.Count().ToString());
            return data;
        }

method of performing Ajax:

        public IActionResult All()
        {ViewBag.A = HttpContext.Session.GetString("A");
            return View();
        }

All view which I tried to return number of records returned by Ajax (@ViewBag.A):

<form>
<div class="col-xs-2">
<label for="ex2">Id</label>
<input class="form-control" type="text" id="sidd" name="sid">
</div>
<input type="button" value="بحث" id="search" class="btn btn-default">
</form>

<div>
<ul class="nav nav-tabs" style="color:black;">
<li class="in active" style="color:black;"><a data-toggle="tab" href="#home">@ViewBag.A Actions</a></li>
<li><a data-toggle="tab" href="#menu1" style="color:black;">Holidays</a></li>
</ul>
@*Some code*@
<div class="tab-content" id="col-md-12">
<div id="home" class="tab-pane fade in active">
<table class="table">
<thead>
<tr>
<th>
Id
</th>
<th>
Name
</th>
</tr>
</thead>
<tbody id="ActionsEtags"></tbody>
</table>
</div>
</div>
</div> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}<script>$(function () {$('#search').on('click', function () { var sid = $('#sidd').val();$.ajax({ type: "GET", url: "/MyController/ActionsHeaderE?sid=" + sid, success: function (data) {$("#ActionsEtags").empty();$.each(data, function (index, item) { console.log(item);$('<tr id="Row' + index + '">' + '<td>' + item.Id + '</td>' + '<td>' + item.Name + '</td>' + '</tr>').appendTo($('#ActionsEtags')); }); } }); }); });</script> }

But when I pressed Search button the records are returned successfully but with blank space for @ViewBag.A. Why? and How to solve please?

How can I return a 404 status code by app.UseStatusCodePages?

$
0
0

These days I am handling 404 Not Found by Asp.Net Core .

As we know, there are several ways to achieve this: app.UseStatusCodePagesWithRedirects/app.UseStatusCodePagesWithReExecute/app.UseStatusCodePages .

I have to choose the app.UseStatusCodePages for I need to localizer the page by URL.

For example:

https://www.microsoft.com/en-us/microsoft-365/

The 'en-us' in URL just for deciding the language of the page.

Here is my code in startup.cs

app.UseStatusCodePages(async context =>
            {
                string currentCulture = "";
                if (context.HttpContext.Request.Path.Value.Split('/').Length < 2)
                {
                    currentCulture = "en";
                }
                else
                {
                    string LanguageGet = context.HttpContext.Request.Path.Value.Split('/')[1];
                    currentCulture = SupportedCultures.Find(X => X.Name == LanguageGet) == null ? "en" : SupportedCultures.Find(X => X.Name == LanguageGet).Name;
                }
                var redirectPath = "/" + currentCulture + "/Error/" + context.HttpContext.Response.StatusCode;
                context.HttpContext.Response.Redirect(redirectPath);
            });

Now it works.

However, after I input a URL which does not exist. The header shows a 302 status code in the Network of Chrome DevTools but not a 404 status code.

Well, when I input the URL(https://www.microsoft.com/en-us/123.html), the header shows a right 404 status code in the Network of Chrome DevTools.

I searched about this on Google. Someone said I should add a ProducesResponseType in the controller, just like this:

public class OthersController : Controller
    {
        [Route("{culture=en}/Error/{code:int}")]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public IActionResult Error(int code)
        {            
            return View(code);
        }
    }

Well, it doesn't work any. I want to solve this because of SEO.

How can I solve this? Thank you.


.NET Core REST API

$
0
0

Hello, I have to create REST API in .NET CORE 3.0 without using Entity Framework.

Can anyone tell me a link or put some code about it?

Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'

$
0
0

I am trying to work through the Contoso University example application.  I have simply copied the Startup.cs class statements:

services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

I receive the error:

DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method. 'UseSqlServer' accepting a first argument of type 'DbContextOptionBuilder' could be found ( are you missing a using directive or an assemply reference)

What do I need to do to move forward?

Thanks

ASP.NET Core 2.2 CORS No 'Access-Control-Allow-Origin' header

$
0
0

I'm having trouble to consume a ASP.NET Core 2.2 web api.

This javascript code below works well, I can get all clients fine

fetch('https://10.20.0.20:8081/api/clients/list').then(data => { data.json().then(dt=>{console.log(dt)}) }).catch(error => { console.log(error)});

But this one doesn't work

fetch('https://10.20.0.20:8081/api/clients/list',{ "headers": {"content-type": "application/json"}}).then(data => { data.json().then(dt=>{console.log(dt)}) }).catch(error => { console.log(error)});

Well... It is what I have in my ConfigureServices method from Startup.cs

services.AddCors(setup => setup.AddPolicy("AllowAll", builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials()));

My first line after Configure method from Startup.cs

app.UseCors("AllowAll");

<div>When I comment this line above both fetch stop working.</div> <div> </div> <div>I did this litle test just because I'm using angular to consume this API and I facing this same problem.</div> <div> </div><div>Error message:</div> <div>Access to fetch at 'https://10.20.0.20:8081/api/clients/Listar' from origin 'https://10.20.0.20:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.</div>

FileResult method is not finding text file in wwwroot to download

$
0
0

Good Afternoon!

I'm having an issue with my FileResult method not finding a text file in my wwwroot. The method is currently working up until the return statement. The text file is being created in wwwroot with the correct information in it. The issue now is when I click the button to "download the deck" it pops up an error about not being able to find the file. It makes no sense because if I copy the path from the error message into my file explorer it opens up the file! I'll post the relevant code and error message. Any help would be appreciated!

public FileResult DownloadDeck(int deckId)
        {
            var deck = _deckRepository.Decks.Where(d => d.DeckId == deckId).FirstOrDefault();
            var fileName = deck.DeckName + ".txt";
            string filePath = _hostingEnvironment.WebRootPath + "\\DeckText\\" + fileName;

            var memory = new MemoryStream();
            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.WriteLine("//Main Deck");
                foreach (KeyValuePair<string, int> entry in CurDeck.GetCardDictionary(deck.MainDeckCards))
                {
                    sw.WriteLine(entry.Value + " (" + entry.Key + ")");
                }
                sw.WriteLine("//Extra Deck");
                foreach (KeyValuePair<string, int> entry in CurDeck.GetCardDictionary(deck.ExtraDeckCards))
                {
                    sw.WriteLine(entry.Value + " (" + entry.Key + ")");
                }
                sw.Close();
            }

            return File(filePath, "text/plain","Download"+fileName);

        }

Error Message

    

System.IO.FileNotFoundException: Could not find file: C:\Users\chunk\OneDrive\Documents\ChronoclashWebsite\CC Code\ChronoClashDatabase\ChronoClashDeckBuilder\ChronoClashDeckBuilder\wwwroot\DeckText\Test full deck.txt
File name: 'C:\Users\chunk\OneDrive\Documents\ChronoclashWebsite\CC Code\ChronoClashDatabase\ChronoClashDeckBuilder\ChronoClashDeckBuilder\wwwroot\DeckText\Test full deck.txt'
   at Microsoft.AspNetCore.Mvc.Infrastructure.VirtualFileResultExecutor.ExecuteAsync(ActionContext context, VirtualFileResult result)
   at Microsoft.AspNetCore.Mvc.VirtualFileResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Upload image array with other fields, not just images.

$
0
0

I currently have the following:

@page
@model pcore31.AddimgModel

@{
    Layout = null;
}

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width" /><title>Addimg</title></head><body><h4>Petimg</h4><hr /><div class="row"><div class="col-md-4"><form enctype="multipart/form-data" method="post"><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="Petimg.PetName" class="control-label"></label><input asp-for="Petimg.PetName" class="form-control" /><span asp-validation-for="Petimg.PetName" class="text-danger"></span></div><div class="form-group"><label asp-for="Upload1" class="control-label"></label><input asp-for="Upload1" class="form-control" type="file" /></div><div class="form-group"><label asp-for="Upload2" class="control-label"></label><input asp-for="Upload2" class="form-control" type="file" /></div><div class="form-group"><input type="submit" value="Create" class="btn btn-primary" /></div></form></div></div><div><a asp-page="Index">Back to List</a></div>

    @section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }</body></html>

And code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using pcore31.Models;
using pcore31.Helpers;
using System.IO;

namespace pcore31
{
    public class AddimgModel : PageModel
    {
        private readonly pcore31.Models.DatabaseContext _context;
        private IWebHostEnvironment _environment;
        private string fileName;
        //private string filename;

        public AddimgModel(pcore31.Models.DatabaseContext context, IWebHostEnvironment environment)
        {
            _context = context;
            _environment = environment;

        }

        public IActionResult OnGet()
        {
            return Page();
        }

        [BindProperty]
        public Petimg Petimg { get; set; }
        [BindProperty]
        public IFormFile Upload1 { get; set; }
        [BindProperty]
        public IFormFile Upload2 { get; set; }


        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            int k = -1;
            int j = 0;
            string[] items = new string[2];
            string[] newfile = new string[2];
            Lqtest csql = new Lqtest();
            var idcount = csql.Idcount();
            string stringcount = idcount.ToString();
            foreach (IFormFile postpic in Request.Form.Files)
            {
                k = k + 1;
                j = j + 1;
                string sj = j.ToString();
                if (postpic == null)
                {
                    items[k] = "";
                    newfile[k] = "";
                }
                else
                {
                    items[k] = postpic.Name.ToString();
                    int thisid = idcount + j;
                    string thiscount = thisid.ToString();

                    var filename = $"{postpic.FileName}";
                    Array getparts = StrHelper.SplitString(filename);
                    string parta = getparts.GetValue(0).ToString();
                    string partb = getparts.GetValue(1).ToString();

                    newfile[k] = parta + thiscount + "." + partb;
                    var file = Path.Combine(_environment.ContentRootPath, "wwwroot\\images\\upload", newfile[k]);
                    using (var fileStream = new FileStream(file, FileMode.Create))
                    {
                        await postpic.CopyToAsync(fileStream);
                    }
                }


            }
            Petimg.PetName = StrHelper.Ucfirst(Petimg.PetName);
            Petimg.Petpic1 = $"{newfile[0]}";
            Petimg.Petpic2 = $"{newfile[1]}";
            _context.Petimg.Add(Petimg);
            await _context.SaveChangesAsync();

            return RedirectToPage("./Index");
        }
    }
}

This all works.

My question is how do I convert this to an array, like:

@page
@model pcore31.AddimgModel

@{
    Layout = null;
}

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width" /><title>Addimg</title></head><body><h4>Petimg</h4><hr /><div class="row"><div class="col-md-4"><form enctype="multipart/form-data" method="post"><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="Petimg.PetName" class="control-label"></label><input asp-for="Petimg.PetName" class="form-control" /><span asp-validation-for="Petimg.PetName" class="text-danger"></span></div><div class="form-group"><input asp-for="Upload[]" class="form-control" type="file" /></div><div class="form-group"><input asp-for="Upload[]" class="form-control" type="file" /></div><div class="form-group"><input type="submit" value="Create" class="btn btn-primary" /></div></form></div></div><div><a asp-page="Index">Back to List</a></div>

    @section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }</body></html>

How do I change the bonding to reflect an array of files:

// Currently I have:
       [BindProperty]
        public Petimg Petimg { get; set; }
        [BindProperty]
        public IFormFile Upload1 { get; set; }
        [BindProperty]
        public IFormFile Upload2 { get; set; }


//  And what would this change to:
foreach (IFormFile postpic in Request.Form.Files)  ???

Thanks

And I am not wanting

type="file" multiple 

I want the array, as files can come from more than one folder.

Viewing all 9386 articles
Browse latest View live


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