How To Dynamic Upload multiple files with extra detail of model in asp.net core

 How To Dynamic Upload multiple files with extra detail of model in asp.net core 



1). firstly create Model File 


namespace MyModel
{
    public class InsertModel
    {
        public string Name { get; set; }
        public List<uploadmodel> uploadmodels { get; set; }
    }
    public class uploadmodel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public IFormFile File { get; set; }
    }
}


2).Create Action method of Get and Post Request

        public IActionResult UploadModel()
        {
            InsertModel insertModel = new InsertModel();
            insertModel.uploadmodels = new List<uploadmodel>();
            for (int i = 0; i < 3; i++)
            {
                insertModel.uploadmodels.Add(new uploadmodel());
            }
            
            return View(insertModel);

        }
        [HttpPost]
        public IActionResult UploadModel(InsertModel insertModel)
        {
            return View();
        }

3).Create View Of Action 

@model MyModel.InsertModel

@{
    ViewData["Title"] = "UploadModel";    
}

<h1>UploadModel</h1>

<h4>InsertModel</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="UploadModel" enctype="multipart/form-data" method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="Name" class="control-label"></label>
                <input asp-for="Name" class="form-control" />
                <span asp-validation-for="Name" class="text-danger"></span>
                @{
                    if (@Model.uploadmodels != null)
                    {
                        for (int i = 0; i < Model.uploadmodels.Count; i++)  
                        {
                         @Html.HiddenFor(m => m.uploadmodels[i].Id, new { id = "hidden"+i })  
                         @Html.TextBoxFor(m=> m.uploadmodels[i].Name, new { id = "hidden"+i })
                         @Html.TextBoxFor(m=> m.uploadmodels[i].File, new { id = "hidden"+i                                                  ,@type="File"})
                        }
                    }
                }
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-action="Index">Back to List</a>
</div>


How to sent authorized header attribute value using c# .net httpclient for third party api call of oauth 2.0

How to sent authorized header attribute value using C# .NET HTTP client for third party API call of OAuth 2.0

For call token From Authorized Header we use following code


using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Web;
using RestSharp;
using System.Security.Authentication;
using CustomProject.DataEntity.ExtendedEntities;
using System.Web.Script.Serialization;

namespace CustomProject.Api
{

    public class CustomProjectToken
    {

                string Client_id = System.Configuration.ConfigurationManager.AppSettings["Client_id"];
                string Client_secret = System.Configuration.ConfigurationManager.AppSettings["Client_secret"];
                string Grant_type = System.Configuration.ConfigurationManager.AppSettings["Grant_type"];
                string BaseUrl = System.Configuration.ConfigurationManager.AppSettings["BaseUrl"];
                string TokenUrl = System.Configuration.ConfigurationManager.AppSettings["TokenUrl"];
                public static string Token = "";
                public async System.Threading.Tasks.Task<TokenResponse> getTokenAsync()
                {
                 var handler = new HttpClientHandler();
                    handler.ServerCertificateCustomValidationCallback = 
                    (requestMessagecertificatechainpolicyErrors) => true;
                    using (var httpClient = new HttpClient(handler))
                    {
                  using (var request = new HttpRequestMessage(new HttpMethod("POST"),
                         BaseUrl + TokenUrl))
                    {
                var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes
               (Client_id + ":" + Client_secret));
               
               request.Headers.TryAddWithoutValidation("Authorization"$"Basic 
               {base64authorization}");
               
               request.Content = new StringContent("grant_type=" + Grant_type);
                 
               request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse
               ("application/x-www-form-urlencoded");
                   
                ServicePointManager.Expect100Continue = true;
               
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
               
                var response = await httpClient.SendAsync(request);
               
                var payload = JsonConvert.DeserializeObject<TokenResponse>
               (await response.Content.ReadAsStringAsync());
               
               Token = payload.access_token;
               return payload;
                        }
                    }
                }
            }
        }




models:-
public class TokenResponse { public string access_token { set; get; } public string token_type { set; get; } public string expires_in { set; get; } }







how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys


There is a way to find based of multiple key find duplicate records in angular or javascript

 
getDuplicate(itemskeys) {
        let duplicates = [];
        for (let i = 0i < items.lengthi++) {
            let matchkey = 0;
            for (let j = 0j < keys.lengthj++) {
                if ((i < (items.length - 1)) && items[i + 1][keys[j]].toLowerCase() === items[i][keys[j]].toLowerCase()) {
                    matchkey++;
                }
            }
            if (matchkey === keys) {
                duplicates.push(items[i]);
            }
        }
        return duplicates;
    }

Example:
const duplicatethis.getDuplicate(CounterParty, ['OperatorId''TCID']);

















Featured Post

How To Dynamic Upload multiple files with extra detail of model in asp.net core

 How To Dynamic Upload multiple files with extra detail of model in asp.net core  1). firstly create Model File  namespace MyModel {     pub...

Popular Posts