How to get the value of @DropDownListFor in [HttpPost] at controller [duplicate]

I got the Solution for above issue. Model(MotorInput.cs) public int CatID { get; set; } Controller(UserController.cs) //To load in View page setting to viewBag from database public ActionResult Motors() { this.ViewBag.CatID = new SelectList(this.db1.motors, “id”, “cat”); return View(); } View(Motors.cshtml) @model BLL.Models.MotorInput @{ ViewBag.Title = “Motors”; Layout = “~/Views/Shared/_UserLayout.cshtml”; } @using (Html.BeginForm()) { @Html.DropDownList(“CatID”, (SelectList)ViewData[“CatID”], … Read more

How to write code that runs once

Make hicnExists a nullable static class-level variable. Test to see if it’s null when your function is called. If it’s null, run your query and set the value. Once the value is set, the query will not run again for the remainder of the current transaction. If you want to cache the result between transactions, … Read more

Smtp authentification required [duplicate]

You need to tell the SMTP client that you will not be using your windows credentials to access the SMTP, so add smtpClient.UseDefaultCredentials = false; above this line of code smtpClient.Credentials = new NetworkCredential(“[email protected]”, “password”); Also, gmail doesn’t allow impersonation, so mailMessage.From = new MailAddress(“[email protected]”); will have no effect – the emails will still appear … Read more