Posts

Best Way to manage session in .NET core centrally.

Create this common class and create 2 method for one session One method is for set value and second method is used for get value from session. This is also known as extension method concept in C# .NET. After creating this class you can simply set and get value from session. example : HttpContext.Session.InstitutionId(Id);  -> Here I we are set value in session. Id =Convert.ToInt32(HttpContext.Session.PortalUserId()) -> here we are getting value from session. using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text.Json; using System.Web; namespace Z.App.Helper {     public static class CentralSession      {         private static string PORTAL_USER_ID = "PortalUserId";         private static string INSTITUTION_ID = "InstitutionId";         private static string ISADMIM = "IsAdmin";          ...

Best way to submit from using Ajax post method in ASP.NET MVC

  jQuery Code :   function Login() {         debugger;         var hasError = Validate("#divUserLoginContainer");         if (!hasError) {             var url = '/UserLogin/SignIn';         }         $.post(url, $('#frmUserLogin').serialize(), function (data) {             if (data.isSuccess == true) {                 debugger;                 swal({                     title: "Success",                     text: data.message,                     icon: "success",                 })                     .the...

Get error message from ModelState in c# mvc

public async Task<JsonResult> SignIn(UserLoginViewModel model)      {        if (!ModelState.IsValid)       {               _returnModel.Message  = ModelState.FirstOrDefault(x=>x.Value.Errors.Any()).Value.Errors.FirstOrDefault().ErrorMessage;        return Json(_returnModel);         }      return Json(_returnModel);   }

Cast any C# object to specific type of object.

ReturnModel returnModel = new ReturnModel();  returnModel = await fileDownloadService.GetUploadedFiles(URL);   List FilesList = new List ();   var Filelist = returnModel.Data as List ;  // Here I want to convert returnModel.Data into the List

Display Image preview on Edit time

Controller Code  public async Task<IActionResult> EditBlog(string Id)         {             DropDownInitialize();             _returnModel = await _blogDetailsServices.GetBlog(Id);             if (_returnModel.IsSuccess)             {                 string path = ((EduWeb.Data.Entity.tblblogdetails)_returnModel.Data).ImagePath; // this Line Represent path coming from database                   int pos = path.LastIndexOf("\\") + 1;                 ViewBag.image = path.Substring(pos, path.Length - pos); // Adding  in View Bag                 return View(_returnModel.Data);             }             else ...

How to rollback and commit transection in Asp.net MVC

 Example Of Rollback And Commit Transection In Asp.Net MVC ...  using (var _Context = new IRISDevMultiTenantEntities1())             {                 using (DbContextTransaction dbTransection = _Context.Database.BeginTransaction()) // Create a object of DbContextTransaction                 {                     try                     {                         tblCompany obj = new tblCompany();                         obj.Company_Name = CompanyName;                         obj.Logo_Filename = null;                         obj.Date_Cre...

jQuery toasted message example

Image
 Package  :  For Toasted message you need to download toast package from nugate  package manager .   <package id="toastr" version="2.1.1" targetFramework="net472" /> Import three script in page :  <link href="~/Content/toastr.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="~/Scripts/toastr.js"></script> Example :   $.ajax({             type: "POST",             url: '@Url.Action("SubmitData", "Emplyee")',             data: FormData.serialize(),             success: function (data) {                 debugger                 if (data.success == true) {                     toastr.success('Su...

Search Record From Table Using jQuery in Asp.net core MVC

Table Code : <div class="row">     <div class="col-md-12">         <div class="card">             <div class="card-body">                 <div class="">                     <table id="tblAccount" class="table table-bordered">                         <thead>                             <tr>                                 <th>Account </th>                                 <th>Website</th>                             ...

Display Multi-pal List in Single View in c# MVC

 Display Student Details and Student Marks in Single view StudentMarksViewModel  public class StudentMarksViewModel     {         public int Id { get; set; }         public Nullable<int> Maths { get; set; }         public Nullable<int> Phy { get; set; }         public Nullable<int> chemestriy { get; set; }     } StudentDetailViewModel public class StudentViewModel     {         public int StudentId { get; set; }         public string Name { get; set; }         public string Streem { get; set; }         public string ContactNumber { get; set; }         public string Address { get; set; }     } TwoListViewModel  public class TwoListViewModel     {         public IEnumerable<Final_Form_Student> Final_Stude...

Using Store Procedure Select Data From Two Table And Get List In MVC

 Controller  public ActionResult StudentDetail()         {             var Data = _context.Database.SqlQuery<Your Class >("YourStoreProcedre Name").ToList();             return View(Data);         } View @model IEnumerable<interview2.Models.StudentViewModel> @{     ViewBag.Title = "StudentDetail"; } <h2>StudentDetail</h2> <p>     @Html.ActionLink("Create New", "Create") </p> <table class="table">     <tr>         <th>             @Html.DisplayNameFor(model => model.Maths)         </th>         <th>             @Html.DisplayNameFor(model => model.Phy)         </th>         <th>         ...

Insert Data Of RaddioButton in DataBase and Get Data From DataBase in RadioButton

 Insert Data in DataBase  Controller  [HttpPost]         public ActionResult Create(Final_Form model, bool Csharp, bool Fsharp, bool JAVA, bool php)         {             Final_Form final_Form = new Final_Form();             final_Form.Intrested_C_ = (Csharp==true)? true:false;             final_Form.Intrested_F_ = (Fsharp==true)? true:false;             final_Form.Intrested_JAVA = (JAVA==true)?true:false;             final_Form.Intrested_PHP = (php==true)?true:false;             final_Form.Gender = model.Gender;//radioButton              _context.Final_Form.Add(final_Form);             _context.SaveChanges();             return RedirectToAction("index");   ...

CheckBox in Asp.Net MVC (Insert Data of CheckBox in Database and GetData Of checkBox From DataBase)

Insert Data of CheckBox in Database  Controller        [HttpGet]           public ActionResult Create()         {             return View();         }        [HttpPost]         public ActionResult Create(Final_Form model, bool Csharp, bool Fsharp, bool JAVA, bool php)         {             Final_Form final_Form = new Final_Form();             final_Form.Intrested_C_ = (Csharp==true)? true:false;             final_Form.Intrested_F_ = (Fsharp==true)? true:false;             final_Form.Intrested_JAVA = (JAVA==true)?true:false;             final_Form.Intrested_PHP = (php==true)?true:false;             _context.Final_Form.Add(final_F...

Contains function in LINQ C#

Image
Contains In LINQ .  Example :             string[] names = { "Alex", "Apu", "sanju", "Bhoomi", "Riya", "Anu" };             IEnumerable<string> Rsult = from nm in names                                         where nm.Contains("A")                                         select nm;             foreach (string p in Rsult)             {                 Response.Write(p + "</br>");             }

LINQ StartWith() EndWith() use in Query C# (

Image

LINQ AND OR Operators in C# (In Hindi)

Image
OR Operator int[] Age = { 20, 32, 45, 60, 90, 10, 5 };             var res = from no in Age                       where no > 20 || no % 2 == 0                       select no;             foreach (var item in res)             {                 Response.Write(item + "</br>");             }   return View(); And Operator int[] Age = { 20, 32, 45, 60, 90, 10, 5 };             var res = from no in Age                       where no > 20  &&  no % 2 == 0                       select no;             foreach (var...

What is LINQ and INTRODUCTION of LINQ

Image
·        Full Form Of LINQ  Language Integrated Query ·        Query expressions can be used to query and to transform data from any LINQ-enabled data source. For example, a single query can retrieve data from a SQL database, and produce an XML stream as output.   ·        A query is not executed until you iterate over the query variable, for example, in a  foreach  statement .   ·        XML documents:  LINQ to XML   ·        ADO.NET Entity Framework:  LINQ to entities Example int[] numbers = { 20, 32, 45, 60, 90, 10, 5 };             var result = from s in numbers                          where s > 20                          select s; ...

AutoComplete Text Box in C# MVC using jQuery AutoComplete Method

First Add one Text Box <div class="ui-widget">             <div class="col-md-3">                 @*<input type="number" placeholder="Enter Contact Student Contact no" class="form-control" name="ContactNo" id="ContactNo" />*@                 @Html.TextBoxFor(model => model.ContactNo, htmlAttributes: new { @class = "form-control", @required = "required" })             </div>         </div> Use Jquery AutoComplete method Creating one array For Json  var AvailabelContactNumbers = [];             $.ajax({                     type: 'Get',                 url: '@Url.Action("GetContactList", "StudentExams")',                 success: function...

#2 What is class in object oriented programming c# (in hindi)

Image

object oriented programming

Image

Address Tag in Html

Image