Posts

Showing posts from February, 2020

Cookies in MVC

Creating Cookie in Clint side Browser .  HttpCookie cookie = new HttpCookie("Cookie Name");//cookie is object of HttpCookie                 cookie.Value = md.Userid + md.password;//Set value of cookie                 HttpContext.Response.Cookies.Add(cookie);//Add cookie in Browser                 cookie.Expires.AddDays(1);    //Set Time of Cookie Expiring Time Expiring Cookie . [Route("out")]         public ActionResult logout()         {             HttpCookie cookie = new HttpCookie("LoginCookie");             if (Request.Cookies["LoginCookie"] != null)             {                 HttpCookie myCookie = new HttpCookie("LoginCookie");       ...

All The Regular Expression For Validation In MVC

Model Code :  [RegularExpression(@"^[a-zA-Z\s]+", ErrorMessage ="pleace enter Valied name ")]         [Required(ErrorMessage ="First Name Required")]         public string FirstName { get; set; }  [RegularExpression(@"^[a-zA-Z\s]+", ErrorMessage ="pleace enter Valied name ")]         [Required(ErrorMessage ="Last name Required")]         public string LastName { get; set; }          [Required(ErrorMessage ="Age Required ")]         [Range(18,95,ErrorMessage ="Pleace Enter valied Age")]         public string Age { get; set; }         [Required(ErrorMessage ="Password Required")]         [RegularExpression(@"((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})", ErrorMessage ="pleace enter special cherector, number ,minimum7 chearector")]     ...

Easy And Best Way to upload image in DataBase --MVC

Controller Code:    [HttpGet]         public ActionResult CreateAccount()         {             return View();         }         [Route("CreateNewAccount")]         [HttpPost]         public ActionResult CreateAccount(MyLogin log , HttpPostedFileBase file)         {             FormDbEntities db = new FormDbEntities();             var userdata = db.tbl_Login.Where(x => x.Userid == log.Userid).Count();//cheking for not use same user name             if(userdata>0)             {                 ViewData["usererro"] = "This User name Alredy used";             }     ...

Image Uploading In Data base MVC

Code Of Controller :  public ActionResult imageUpload()         {             return View();         }         [HttpPost]         public ActionResult imageUpload(tbl_ImageUpload imagemodel , HttpPostedFileBase file)//imagemodel is object of imageUpload Model and File is Object off HttppostFileBase File Is same name or id of button mostly importantn         {             TestDbEntities db = new TestDbEntities();//object of database file entity             tbl_ImageUpload tbl = new tbl_ImageUpload();//object of table             var allowedExtention = new[] { ".JPG",".PNG",".JPG",".PNG",".GIF",".WEBP",".TIFF",".PSD",".RAW",".BMP",".HEIF",".INDD", ".Png", ".jpg", "  jpeg" };//set the Extention             ...

Send Mail To user using semp in MVC

Send Mail To user using semp in MVC Code:  [Route("CountactUs")]         public ActionResult CountactUs()         {             return View();         }         [Route("CountactUs")]         [HttpPost]         public ActionResult CountactUs(Mymail md)         {             FormDbEntities db = new FormDbEntities();             tbl_mail tb = new tbl_mail()             {                 FirstName=md.FirstName,                 Gmail=md.Gmail,                 Body=md.Body,                 Subject=md.Subject     ...

Validate If user create same user name account than get Error -MVC

Code        [Route("CreateNewAccount")]         [HttpGet]         public ActionResult CreateAccount()         {             return View();         }         [Route("CreateNewAccount")]         [HttpPost]         public ActionResult CreateAccount(MyLogin log)         {             FormDbEntities db = new FormDbEntities();             var userdata = db.tbl_Login.Where(x => x.Userid == log.Userid).Count();             if(userdata>0)             {                 ViewData["usererro"] = "This User name Alredy used";             }     ...

Session Use in MVC

Example of Session Code :  [Route("Sesstion")]         public ActionResult mymethod5()         {             Session["Mysesstion"] = "My First sesstion Demo";             return View();//RedirectToAction("Index", "Teacher");         } CsHtml : @session["Mysesstion"]

TempData Example in MVC

Use Of TempData Code  [Route("TempData")]         public ActionResult mymethod4()         {             TempData["Mytemp"] = "My Temp Data";             return View();         } csHTML @{     ViewBag.Title = "mymethod3"; } @ViewData["viewdata"] <h2>mymethod3</h2> <h1>Temp Data   : @TempData["mytemp"]</h1> Note : TempData is use to send one action method to another Action method. 

ViewData MVC

Example Of View Data Code [Route("ViewData")]         public ActionResult mymethod3()         {             ViewData["viewdata"] = "My Example View Data" + DateTime.Now.ToString();             return View();         } csHTML @ViewData["viewdata"] <h2>mymethod3</h2> <h1>Temp Data   : @TempData["mytemp"]</h1>

ViewBag Example in MVC

Use Of  ViewBag Code [Route("ViewBag")]         public ActionResult mymethod2()         {             ViewBag.mybag = "Hello my View bag Example";             return View();         } CsHTML <h2>mymethod2</h2> @ViewBag.mybag @ViewData["viewdata"]

Registration Form in MVC

Code   [Route("CreateNewAccount")]         [HttpGet]         public ActionResult CreateAccount()         {             return View();         }         [Route("CreateNewAccount")]         [HttpPost]         public ActionResult CreateAccount(MyLogin log)         {             tbl_Login tb = new tbl_Login() //table              {                 FirstName = log.FirstName,                 Userid=log.Userid,                 password=log.password,                 Copassword=log.Copassword,             }; ...

Logout In MVC

Code [Route("out")]         public ActionResult logout()         {             Session["username"] = null;             Session["password"] = null;             return View("Login");         } csHtml   @if (Session["username"] == null && Session["password"] == null)                     {                         <li><a href="~/Account/Login">Login</a></li>                     }                     else                      {                       ...

Check Password and Username Login in MVC

Code :        [Route("Login")]         public ActionResult Login()         {                          return View();         }         [Route("Login")]         [HttpPost]         public ActionResult Login(MyLogin md)         {             Session["username"] = md.ToString();             Session["password"] = md.ToString();             FormDbEntities db = new FormDbEntities();             var data= db.tbl_Login.Where(x => x.Userid == md.Userid && x.password == md.password).Count();             if(data>0)             {     ...

Select Data into the DataBase In ASP.NET MVC

Controller Code  [HttpGet]         public ActionResult List()         {             FormDbEntities db = new FormDbEntities();             List<MyinsertModel> list = new List<MyinsertModel>();             list=db.maindatas.Select(cd => new MyinsertModel() {                 Fnm = cd.Fnm,                 lnm = cd.lnm,                 age = cd.age,                 contactno = cd.contactno,                 contry = cd.contry,                 state = cd.state,                 city = cd.city,             ...

WHAT IS INTERFACE IN C#

Explain interface Interface in C# is a blueprint of a class. It is like abstract class because all the methods which are declared inside the interface are abstract methods. It cannot have method body and cannot be instantiated. It is used  to achieve multiple inheritance  which can't be achieved by class. It is used  to achieve fully abstraction  because it cannot have method body. Its implementation must be provided by class or struct. The class or struct which implements the interface, must provide the implementation of all the methods declared inside the interface. Example using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; interface IStudent {     int subtotal(int s1, int s2, int s3, int s4);     float per(int total);     string grade(float per);       } class Customer : IStudent {         public ...

ABSTRECT CLASS IN C# PROGRAMING

What is Abstrect class An abstract class is a special type of class that cannot be instantiated. An abstract class is designed to be inherited by sub classes that either implement or override its methods. In other words, abstract classes are either partially implemented or not implemented at all. You can have functionality in your abstract class—the methods in an abstract class can be both abstract and concrete. An abstract class can have constructors—this is one major difference between an abstract class and an interface. You can take advantage of abstract classes to design components and specify some level of common functionality that must be implemented by derived classes.  Code of Abstrect class example  using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abstrectClass {     abstract class person     {         public stri...