ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.XSRF Token Size in MVC<p>Hi,</p> <p>Just wanted to know what is the XSRF / CSRF token size in MVC. Googled it but no luck.</p> <p>&nbsp;</p> <p>Thanks in advace.</p>https://www.aspforums.net:443/Threads/181084/XSRF-Token-Size-in-MVC/https://www.aspforums.net:443/Threads/181084/XSRF-Token-Size-in-MVC/Thu, 23 Nov 2017 22:33:27 GMTWhy multiple _RequestVerificationToken used in ASP.Net MVC<p>My application in mvc asp.net for database I am using sql server I had <strong>Cross-Site Request Forgery (CSRF)</strong> in my application for so I put <strong>@Html.AntiForgeryToken()</strong> in view and in controller I add <strong>[ValidateAntiForgeryToken]</strong> I am getting two <strong>RequestVerificationToken</strong> as mention in images</p> <p><img src="https://i.imgur.com/XjdywQ1.png" alt="" width="472" height="150" /></p> <p><strong>In View</strong>&nbsp;</p> <pre class="brush: csharp"> &lt;div class=&#34;login-wrapper&#34;&gt; &lt;div id=&#34;login&#34; class=&#34;login loginpage col-lg-offset-4 col-lg-4 col-md-offset-3 col-md-6 col-sm-offset-3 col-sm-6 col-xs-offset-0 col-xs-12&#34;&gt; &lt;h1&gt;&lt;a href=&#34;#&#34; title=&#34;Login Page&#34; tabindex=&#34;-1&#34;&gt;ESH HRMS&lt;/a&gt;&lt;/h1&gt; @using (Html.BeginForm(&#34;login&#34;, &#34;admin&#34;, FormMethod.Post,new { ReturnUrl = ViewBag.ReturnUrl })) { @Html.AntiForgeryToken() &lt;p&gt; &lt;label for=&#34;user_login&#34;&gt; Username&lt;br /&gt; @Html.TextBoxFor(m =&gt; m.LoginID, new { @class = &#34;input&#34;, @id = &#34;txtUserName&#34;, @placeholder = &#34;UserName&#34;, @size = &#34;20&#34; }) &lt;/label&gt; &lt;/p&gt; &lt;p&gt; &lt;label for=&#34;user_pass&#34;&gt; Password&lt;br /&gt; @Html.TextBoxFor(m =&gt; m.Password, new { @class = &#34;input&#34;, @id = &#34;txtPassword&#34;, type = &#34;password&#34;, @size = &#34;20&#34; }) &lt;/label&gt; &lt;/p&gt; &lt;p&gt; &lt;div class=&#34;g-recaptcha&#34; style=&#34;width:130%;&#34; data-sitekey=&#34;6LdY2TMUAAAAAEmHk8ZeNF3AwdJ8D92Lm-U3LinQ&#34;&gt;&lt;/div&gt; &lt;/p&gt; &lt;p class=&#34;forgetmenot&#34;&gt; &lt;label class=&#34;icheck-label form-label&#34; for=&#34;rememberme&#34;&gt; @Html.CheckBoxFor(m =&gt; m.RememberMe, new { @class = &#34;skin-square-orange&#34;, @id = &#34;rememberme&#34; }) Remember me &lt;/label&gt; &lt;/p&gt; &lt;p class=&#34;submit&#34;&gt; &lt;input type=&#34;submit&#34; name=&#34;wp-submit&#34; id=&#34;btnSubmit&#34; class=&#34;btn btn-orange btn-block&#34; value=&#34;Sign In&#34; /&gt; &lt;/p&gt; } @*&lt;p id=&#34;nav&#34;&gt; &lt;a class=&#34;pull-left&#34; href=&#34;#&#34; title=&#34;Password Lost and Found&#34;&gt;Forgot password?&lt;/a&gt; &lt;a class=&#34;pull-right&#34; href=&#34;ui-register.html&#34; title=&#34;Sign Up&#34;&gt;Sign Up&lt;/a&gt; &lt;/p&gt;*@ &lt;/div&gt; &lt;/div&gt;</pre> <p>In Controller</p> <pre class="brush: csharp"> // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(LoginViewModel model, string returnUrl) { try { if (!ModelState.IsValid) return View(model); if (ValidateHuman()) { string loginID = model.LoginID.ToUpper().TrimEnd(); string password = model.Password; string hashedPassword = AccountManager.PassEncrypt(password); HRMSEntities db = new HRMSEntities(); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); bool userExist = db.LetoUsers.Any(x =&gt; x.Suspend == 0 &amp;&amp; x.Username.ToLower().TrimEnd() == loginID &amp;&amp; x.CompanyId == Utility.CompanyID); if (userExist &amp;&amp; (string.Compare(hashedPassword, db.LetoUsers.First(x =&gt; x.Suspend == 0 &amp;&amp; x.Username.ToLower().TrimEnd() == loginID &amp;&amp; x.CompanyId == Utility.CompanyID).Password.ToString()) == 0)) { // var user = db.LetoUsers.Where(x =&gt; x.Suspend == 0 &amp;&amp; x.Username.ToLower().TrimEnd() == loginID &amp;&amp; x.CompanyId == Utility.CompanyID &amp;&amp; x.Password == hashedPassword).FirstOrDefault(); original var user = db.LetoUsers.Where(x =&gt; x.Suspend == 0 &amp;&amp; x.Username.ToLower().TrimEnd() == loginID &amp;&amp; x.CompanyId == Utility.CompanyID).FirstOrDefault(); var emp = db.Employees.SingleOrDefault(x =&gt; x.Suspend == 0 &amp;&amp; x.Status == 1 &amp;&amp; x.AlternateEmployeeCode == user.EmployeeCode &amp;&amp; x.CompanyId == Utility.CompanyID); //---- Generate Authentication Ticket DateTime cookieIssuedDate = DateTime.UtcNow; LoggedInUser loginUser = new LoggedInUser(); loginUser.EmpID = Convert.ToInt32(emp.EmployeeId); loginUser.UserID = user.LetoUserId; loginUser.UserTypeID = Convert.ToInt32(user.UserTypeId); loginUser.UserName = user.Username; loginUser.EmployeeCode = user.EmployeeCode; loginUser.EmployeeName = emp.FirstName; //FormsAuthentication.SetAuthCookie(user.Username, model.RememberMe); //Session[&#34;UserType&#34;] = Convert.ToInt32(user.UserTypeId); //Session[&#34;UserID&#34;] = user.LetoUserId; //Session[&#34;EmployeeCode&#34;] = user.EmployeeCode; //Session[&#34;UserName&#34;] = user.Username; // Getting New Guid //string guid = Convert.ToString(Guid.NewGuid()); ////Storing new Guid in Session //Session[&#34;AuthenticationToken&#34;] = guid; ////Adding Cookie in Browser //Response.Cookies.Add(new HttpCookie(&#34;AuthenticationToken&#34;, guid)); string userData = JsonConvert.SerializeObject(loginUser); var ticket = new FormsAuthenticationTicket(0, model.LoginID, cookieIssuedDate, cookieIssuedDate.AddMinutes(30),// (model.RememberMe) ? cookieIssuedDate.AddDays(7) : cookieIssuedDate.AddMinutes(30),//FormsAuthentication.Timeout.TotalMinutes), model.RememberMe, userData, FormsAuthentication.FormsCookiePath); string encryptedCookieContent = FormsAuthentication.Encrypt(ticket); var formsAuthenticationTicketCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedCookieContent) { Domain = FormsAuthentication.CookieDomain, Path = FormsAuthentication.FormsCookiePath, HttpOnly = true, Secure = FormsAuthentication.RequireSSL }; // ---- if remember me is checked then the cookie will expire after 7 days else at end of session if (model.RememberMe) formsAuthenticationTicketCookie.Expires = cookieIssuedDate.AddDays(7); System.Web.HttpContext.Current.Response.Cookies.Add(formsAuthenticationTicketCookie); return RedirectToAction(&#34;UserDashBoard&#34;); } else { TempData[&#34;Error&#34;] = &#34;please enter correct username/password..!!&#34;; } } else { TempData[&#34;Error&#34;] = &#34;Incorrect Captcha..!!&#34;; } } catch (Exception ex) { } // If we got this far, something failed, redisplay form //ModelState.AddModelError(&#34;&#34;, &#34;The user name or password provided is incorrect.&#34;); return View(model); } </pre>https://www.aspforums.net:443/Threads/100245/Why-multiple-RequestVerificationToken-used-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/100245/Why-multiple-RequestVerificationToken-used-in-ASPNet-MVC/Wed, 17 Jan 2018 06:50:27 GMTWhat is use of TextBoxFor in ASP.Net MVC Razor<p>hi sir,</p> <p>i want to know why this code is written in mvc in asp.net</p> <pre class="brush: html">&lt;div class=&#34;col-md-2&#34;&gt; &lt;label&gt;Duration in Min&lt;/label&gt; @Html.TextBoxFor(m =&gt; m.DurationInMinutes, new { id = &#34;txtduration&#34;, @class = &#34;form-control txtOnlyNumber&#34;, maxlength = &#34;30&#34; }) &lt;/div&gt;</pre> <p><strong><em>@Html.TextBoxFor(m =&gt; m.DurationInMinutes,</em></strong>&nbsp;why this is used</p>https://www.aspforums.net:443/Threads/881457/What-is-use-of-TextBoxFor-in-ASPNet-MVC-Razor/https://www.aspforums.net:443/Threads/881457/What-is-use-of-TextBoxFor-in-ASPNet-MVC-Razor/Fri, 26 Oct 2018 05:36:04 GMTWhat is the difference between ViewData ViewBag and TempData in ASP.Net MVC<p>What is the difference between ViewData, ViewBag and TempData?</p>https://www.aspforums.net:443/Threads/214089/What-is-the-difference-between-ViewData-ViewBag-and-TempData-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/214089/What-is-the-difference-between-ViewData-ViewBag-and-TempData-in-ASPNet-MVC/Thu, 22 Sep 2016 01:52:46 GMTWhat is the difference between ASP.Net and MVC<p>Hi! What is the difference between asp.net and mvc. Actually I want to learn asp mvc but I do not know if it has more advantages than asp.net (webform) or not ? Thnk you</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/195155/What-is-the-difference-between-ASPNet-and-MVC/https://www.aspforums.net:443/Threads/195155/What-is-the-difference-between-ASPNet-and-MVC/Wed, 03 Aug 2016 02:51:09 GMTWhat is MVC<p>what is &nbsp;MVC .Why we use MVC.</p> <p>&nbsp;</p> <p>how to use MVC...</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/154551/What-is-MVC/https://www.aspforums.net:443/Threads/154551/What-is-MVC/Tue, 08 Jul 2014 05:24:40 GMTWhat is ASP.Net MVC<p>I want to know what is called ASP.NET MVC</p>https://www.aspforums.net:443/Threads/114135/What-is-ASPNet-MVC/https://www.aspforums.net:443/Threads/114135/What-is-ASPNet-MVC/Sat, 22 Sep 2012 10:20:34 GMTWhat is ASP.Net MVC<p>Anyone can describe about MVC technology which is more important for dot net.</p> <p>what is the MVC in Dot net.</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/203145/What-is-ASPNet-MVC/https://www.aspforums.net:443/Threads/203145/What-is-ASPNet-MVC/Tue, 19 Jun 2018 00:58:06 GMTWebcam Error: jQuery(...).webcam is not a function in ASP.Net MVC<h1 class="header"><a title="Capture Image (Photo) from Web Camera (Webcam) in ASP.Net MVC'a" href="https://www.aspsnippets.com/Articles/Capture-Image-Photo-from-Web-Camera-Webcam-in-ASPNet-MVC.aspx">Capture Image (Photo) from Web Camera (Webcam) in ASP.Net MVC</a></h1> <p>First of all, thanks for posting this article.</p> <p>I have downloaded the source code of this article and run that on my localhost, it works fine.</p> <p>Then after, i copied the code and paste that on my project, exactly same, but in my project it is not working. flash popup is not showing.</p> <p>everything works fine except this: this error shows on inspect element(console mode)</p> <p>Uncaught TypeError: jQuery(...).webcam is not a function</p> <p>Please suggest me why ??</p>https://www.aspforums.net:443/Threads/171637/Webcam-Error-jQuerywebcam-is-not-a-function-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/171637/Webcam-Error-jQuerywebcam-is-not-a-function-in-ASPNet-MVC/Thu, 06 Dec 2018 02:01:27 GMTWeb services in mvc<p>Hi,</p> <p>I had done web services successfully in my mvc project.But i don't know how to set access permission for this web service?</p> <p>Thank you.</p>https://www.aspforums.net:443/Threads/619143/Web-services-in-mvc/https://www.aspforums.net:443/Threads/619143/Web-services-in-mvc/Wed, 07 May 2014 03:22:30 GMTWeb API in ASP.Net MVC<p>hi sir/mam</p> <p>i new to web api, i have no idea, how does it work but i need to learn how to write and read in jason format.</p> <p>&nbsp;</p> <p>plz anyone help to learn it faster.</p>https://www.aspforums.net:443/Threads/200615/Web-API-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/200615/Web-API-in-ASPNet-MVC/Sun, 17 Sep 2017 23:54:53 GMTWeb API example in ASP.Net MVC<p>Hi All</p> <p>I'm very new to ASP.net, as well as WebApi's. Ive created my first test WebApi and have used entitiy framework and connected to my SQL database. I build and run the app no problem, but i cant figure out what URL to type in to see my data. PLease can someone point me in the right direction, i know it must be a silly question but i'm stumped and have been scratching my head and trying for ages.</p> <p>many thanks</p> <p>A.j</p>https://www.aspforums.net:443/Threads/118109/Web-API-example-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/118109/Web-API-example-in-ASPNet-MVC/Mon, 15 Jan 2018 23:05:02 GMTWeb API 404 Not found error after chaning from HTTP to HTTPS in ASP.Net MVC<p>Hi All,</p> <p>Please help me to resolve this issue.</p> <p>we a have website like <a href="http://abc.com">http://abc.com</a>&nbsp;recently it changed to <a href="https://abc.com">https://abc.com</a>&nbsp;in iis at webserver.</p> <p>&nbsp;</p> <p>Now the problem is website not working properly, web api's not loading(not getting json response) on https&nbsp;</p> <p>it's redirecting 404 not found&nbsp;</p> <p>please help me to this.</p> <p>&nbsp;</p> <p>Thanks in Advance.</p>https://www.aspforums.net:443/Threads/183668/Web-API-404-Not-found-error-after-chaning-from-HTTP-to-HTTPS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/183668/Web-API-404-Not-found-error-after-chaning-from-HTTP-to-HTTPS-in-ASPNet-MVC/Mon, 28 May 2018 00:35:02 GMTvalidation of captch using input or textbox<p>i want&nbsp; to validate my captch when my form is submitted using javascript function but i cant access it on submit. I cant validate my textbox or input value with the javascript function on submit</p> <pre class="brush: html">&lt;%@ Page Title=&#34;&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/Site1.Master&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;login.aspx.cs&#34; Inherits=&#34;project29.WebForm2&#34; %&gt; &lt;asp:Content ID=&#34;Content1&#34; ContentPlaceHolderID=&#34;head&#34; runat=&#34;server&#34;&gt; &lt;meta charset=&#34;utf-8&#34;&gt; &lt;meta http-equiv=&#34;X-UA-Compatible&#34; content=&#34;IE=edge&#34;&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1&#34;&gt; &lt;/asp:Content&gt; &lt;asp:Content ID=&#34;Content2&#34; ContentPlaceHolderID=&#34;ContentPlaceHolder1&#34; runat=&#34;server&#34;&gt; &lt;body onload=&#34;createCaptcha()&#34;&gt; &lt;asp:Label ID=&#34;batch&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;asp:Label ID=&#34;batch1&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;asp:Label ID=&#34;name&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;asp:Label ID=&#34;type&#34; runat=&#34;server&#34; Text=&#34;&#34; Visible=&#34;false&#34;&gt;&lt;/asp:Label&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css&#34;&gt; &lt;center&gt; &lt;div class=&#34;form-gap&#34;&gt;&lt;/div&gt; &lt;div class=&#34;container&#34;&gt; &lt;div class=&#34;row&#34;&gt; &lt;div class=&#34;col-md-4 col-md-offset-4&#34;&gt; &lt;div class=&#34;panel panel-default&#34;&gt; &lt;div class=&#34;panel-body&#34;&gt; &lt;div class=&#34;text-center&#34;&gt; &lt;h2 class=&#34;text-center&#34;&gt;&lt;b&gt;Sign In&lt;/b&gt;&lt;/h2&gt; &lt;div class=&#34;modal-footer&#34;&gt;&lt;/div&gt; &lt;%-- &lt;p&gt;You can reset your password here.&lt;/p&gt;--%&gt; &lt;div class=&#34;panel-body&#34;&gt; &lt;form id=&#34;register-form&#34; role=&#34;form&#34; method=&#34;post&#34; onsubmit=&#34;validateCaptcha()&#34;&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;div class=&#34;input-group&#34;&gt;&lt;span class=&#34;input-group-addon&#34;&gt;&lt;i class=&#34;fa fa-user&#34;&gt;&lt;/i&gt;&lt;/span&gt; &lt;asp:TextBox ID=&#34;mail&#34; runat=&#34;server&#34; class=&#34;form-control&#34; placeholder=&#34;abc@gmail.com&#34; &gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID=&#34;RequiredFieldValidator1&#34; runat=&#34;server&#34; ErrorMessage=&#34;*&#34; ForeColor=&#34;Red&#34; ControlToValidate=&#34;mail&#34;&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;div class=&#34;input-group&#34;&gt;&lt;span class=&#34;input-group-addon&#34;&gt;&lt;i class=&#34;fa fa-lock&#34;&gt;&lt;/i&gt;&lt;/span&gt; &lt;asp:TextBox ID=&#34;password&#34; runat=&#34;server&#34; class=&#34;form-control&#34; TextMode=&#34;Password&#34; placeholder=&#34;*********&#34;&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID=&#34;RequiredFieldValidator2&#34; runat=&#34;server&#34; ErrorMessage=&#34;*&#34; ForeColor=&#34;Red&#34; ControlToValidate=&#34;password&#34;&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/div&gt; &lt;/div&gt; &lt;input type=&#34;text&#34; placeholder=&#34;Captcha&#34; id=&#34;cpatchaTextBox&#34; class=&#34;form-control&#34; required/&gt; &lt;div id=&#34;captcha&#34;&gt;&lt;/div&gt; &lt;asp:Button ID=&#34;Button1&#34; runat=&#34;server&#34; Text=&#34;Sign In&#34; CssClass=&#34;btn btn-primary btn-block btn-lg&#34; OnClick=&#34;Button1_Click&#34; /&gt; &lt;/div&gt; &lt;p class=&#34;hint-text&#34;&gt;&lt;a href=&#34;forgotpass.aspx&#34;&gt;Forgot Password?&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;%--&lt;div class=&#34;modal-footer&#34;&gt;&lt;/div&gt;--%&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/center&gt; &lt;/form&gt; &lt;/body&gt; &lt;script&gt; var code; function createCaptcha() { //clear the contents of captcha div first document.getElementById(&#39;captcha&#39;).innerHTML = &#34;&#34;; var charsArray = &#34;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!#$%^&amp;*&#34;; var lengthOtp = 6; var captcha = []; for (var i = 0; i &lt; lengthOtp; i++) { //below code will not allow Repetition of Characters var index = Math.floor(Math.random() * charsArray.length + 1); //get the next character from the array if (captcha.indexOf(charsArray[index]) == -1) captcha.push(charsArray[index]); else i--; } var canv = document.createElement(&#34;canvas&#34;); canv.id = &#34;captcha&#34;; canv.width = 100; canv.height = 50; var ctx = canv.getContext(&#34;2d&#34;); ctx.font = &#34;15px Georgia&#34;; ctx.strokeText(captcha.join(&#34;&#34;), 0, 30); //storing captcha so that can validate you can save it somewhere else according to your specific requirements code = captcha.join(&#34;&#34;); document.getElementById(&#34;captcha&#34;).appendChild(canv); // adds the canvas to the body element } function validateCaptcha() { event.preventDefault(); debugger if (document.getElementById(&#34;cpatchaTextBox&#34;).value == code) { alert(&#34;Valid Captcha&#34;) } else { alert(&#34;Invalid Captcha. try Again&#34;); createCaptcha(); } } &lt;/script&gt; &lt;/asp:Content&gt; </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/182238/validation-of-captch-using-input-or-textbox/https://www.aspforums.net:443/Threads/182238/validation-of-captch-using-input-or-textbox/Fri, 11 Oct 2019 00:19:58 GMTValidate Form on Button Click using AngularJS in ASP.Net MVC<p>Hi,</p> <h1 class="header"><a class="title f16" href="https://www.aspforums.net/Threads/213243/Display-Form-Validation-error-message-on-Button-Click-using-AngularJS-in-ASPNet-MVC/">Display Form Validation error message on Button Click using AngularJS in ASP.Net MVC</a></h1> <p>If we can look at into my forum without entering of even single row it was dsiplaying alert message form is valid</p> <p>i don't need</p> <p>my requiremnt is if everything is valid on orders and Items(at least we have enter single row) until then no need to display alert message form is valid</p> <p>Could you please check it and help me</p>https://www.aspforums.net:443/Threads/851604/Validate-Form-on-Button-Click-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/851604/Validate-Form-on-Button-Click-using-AngularJS-in-ASPNet-MVC/Tue, 19 Mar 2019 22:28:31 GMTValidate DropDownList using Client Side and Server Side Validation in ASP.Net MVC<p>Hi I am new to Asp.Net MVC&nbsp;</p> <p>How to create a page like this and Validation using both on server side and Client side.</p> <p>And how The dropdown can be retrieved from DB and Similarly how to get all the radio buttons values from the DB.</p> <p>Afteer Entering the details how to store it in the DB.<br />Kindly help on it...</p> <p><img src="https://i.imgur.com/4RdONrU.jpg" alt="" width="468" height="313" /></p>https://www.aspforums.net:443/Threads/456769/Validate-DropDownList-using-Client-Side-and-Server-Side-Validation-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/456769/Validate-DropDownList-using-Client-Side-and-Server-Side-Validation-in-ASPNet-MVC/Fri, 03 Oct 2014 04:27:03 GMTValidate DropDownList in ASP.Net MVC<p>hi,</p> <p>I'm filling my dropdown using viewbag like as under</p> <pre class="brush: csharp">@Html.DropDownList(&#34;ArticleType&#34;, null, &#34;select&#34;, new { @class = &#34;ddl&#34; }) @Html.ValidationMessageFor(model =&gt; model.ArticleType) [Required(ErrorMessage = &#34;Please enter article category&#34;)] [DisplayName(&#34;Category&#34;)] public string ArticleType { get; set; }</pre> <p>But i'm unable to get required feild error message.Is i'm going wrong?</p> <p>Thank you.</p>https://www.aspforums.net:443/Threads/198849/Validate-DropDownList-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/198849/Validate-DropDownList-in-ASPNet-MVC/Wed, 02 Apr 2014 23:44:42 GMTValidate and retrieve data from Database after Login using AngularJS in ASP.Net MVC<p>I'm having two textboxes, one is username and the other one is password with a button named 'Login'.</p> <p>Whenever the user tries to click on the login button without entering username or password, it must display error messages like "Username is required" and "Password is required". And also whenever the user tries to click on the login button after entering the username and password, it must redirect to the next page saying "Welcome userid : userid &amp; username : username" i.e. it must fetch the corresponding userid based on the username from the database.&nbsp;</p> <p><strong>AngularHome.js :</strong>&nbsp;</p> <pre class="brush: js">var app = angular.module(&#39;homeapp&#39;, []); app.controller(&#34;HomeController&#34;, function ($scope, $http) { $scope.btntext = &#34;Login&#34;; $scope.login = function () { $scope.btntext = &#34;Please wait..!&#34;; $http({ method: &#34;POST&#34;, url: &#39;/Home/userlogin&#39;, data: $scope.user }).success(function (d) { $scope.btntext = &#39;Login&#39;; if (d == 1) { window.location.href = &#39;/Home/dashboard&#39;; } else { alert(d); } $scope.user = null; }).error(function () { alert(&#39;failed&#39;); }) } })</pre> <p><strong>Index.cshtml :</strong>&nbsp;</p> <pre class="brush: html">@{ Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&#34;UTF-8&#34;&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0&#34;&gt; &lt;meta http-equiv=&#34;X-UA-Compatible&#34; content=&#34;ie=edge&#34;&gt; &lt;title&gt;Document&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css&#34; integrity=&#34;sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T&#34; crossorigin=&#34;anonymous&#34;&gt; &lt;script src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;link href=&#34;~/login.css&#34; rel=&#34;stylesheet&#34; /&gt; &lt;script src=&#34;~/script/angular.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;~/script/AngularController/Angularhome.js&#34;&gt;&lt;/script&gt; &lt;style&gt; body { background: -webkit-linear-gradient(left, #1143a6, #00c6ff); } &lt;/style&gt; &lt;/head&gt; &lt;body ng-app=&#34;homeapp&#34; ng-controller=&#34;HomeController&#34;&gt; &lt;section class=&#34;container &#34;&gt; &lt;div class=&#34;main_cont register&#34;&gt; &lt;form role=&#34;form&#34; name=&#34;loginForm&#34; novalidate&gt; &lt;div class=&#34;login-panel&#34;&gt; &lt;h3 class=&#34;login-heading&#34;&gt;&lt;/h3&gt; &lt;div class=&#34;row&#34;&gt; &lt;div class=&#34;col-md-12 col-sm-12&#34;&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;input type=&#34;text&#34; class=&#34;form-control&#34; placeholder=&#34;Username&#34; ng-model=&#34;user.username&#34; autofocus=&#34;autofocus&#34; required /&gt; &lt;span class=&#34;red-text&#34; ng-if=&#34;loginForm.username.$error.required &amp;&amp; loginForm.email.$dirty&#34;&gt; &lt;br&gt;Username is required&lt;br&gt; &lt;/span&gt; &lt;/div&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;input type=&#34;password&#34; class=&#34;form-control&#34; placeholder=&#34;Password&#34; ng-model=&#34;user.password&#34; required /&gt; &lt;span class=&#34;red-text&#34; ng-if=&#34;loginForm.password.$error.required&#34;&gt; &lt;br&gt;Password is required&lt;br&gt; &lt;/span&gt; &lt;/div&gt; &lt;div class=&#34;float-right&#34;&gt; &lt;input type=&#34;submit&#34; class=&#34;btn btn-primary&#34; value=&#34;{{btntext}}&#34; ng-click=&#34;login()&#34; /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/section&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong>dashboard.cshtml :</strong></p> <pre class="brush: html">@{ Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width&#34; /&gt; &lt;title&gt;dashboard&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;h1&gt;WelCome @Session[&#34;user&#34;]&lt;/h1&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong>user.cs :</strong></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace AnguarLogin.Models { public class user { public string username { get; set; } public string password { get; set; } } }</pre> <p><strong>db.cs :</strong></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Data; using System.Configuration; using AnguarLogin.Models; namespace AnguarLogin.database_Access_Layer { public class db { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;ERPConnectionString&#34;].ConnectionString); public int userlogin(user us) { SqlCommand com = new SqlCommand(&#34;Sp_User_login&#34;, con); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue(&#34;@Username&#34;,us.username); com.Parameters.AddWithValue(&#34;@Password&#34;,us.password); SqlParameter oblogin = new SqlParameter(); oblogin.ParameterName = &#34;@Isvalid&#34;; oblogin.Direction = ParameterDirection.Output; oblogin.SqlDbType = SqlDbType.Bit; com.Parameters.Add(oblogin); con.Open(); com.ExecuteNonQuery(); int res = Convert.ToInt32(oblogin.Value); con.Close(); return res; } } }</pre> <p><strong>HomeController.cs :</strong></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using AnguarLogin.Models; using System.Data; namespace AnguarLogin.Controllers { public class HomeController : Controller { // GET: /Home/ database_Access_Layer.db dblayer = new database_Access_Layer.db(); public ActionResult Index() { return View(); } public ActionResult dashboard() { return View(); } public JsonResult userlogin(user us) { string result = Convert.ToString(dblayer.userlogin(us)); if (result==&#34;1&#34;) { Session[&#34;user&#34;] = us.username; } else { result = &#34;Email or Password is wrong&#34;; } return Json(result,JsonRequestBehavior.AllowGet); } } } </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/134148/Validate-and-retrieve-data-from-Database-after-Login-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/134148/Validate-and-retrieve-data-from-Database-after-Login-using-AngularJS-in-ASPNet-MVC/Tue, 16 Apr 2019 23:54:50 GMTUsing ViewModel over Model in ASP.Net MVC<p>Hi</p> <p>why viewModel is need?</p> <p>we have Model to display&nbsp; data to view in mvc</p> <p>&nbsp;</p> <p>Please Explain&nbsp;</p>https://www.aspforums.net:443/Threads/126418/Using-ViewModel-over-Model-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/126418/Using-ViewModel-over-Model-in-ASPNet-MVC/Fri, 14 Sep 2018 04:39:08 GMTUsing Url.Action method in ASP.Net MVC<h2><em>The resource cannot be found.</em></h2> <p><em>&nbsp;i have controller viewmodel and view</em></p> <p><em>from code in controller when i click the view name and go to view the cshtml file gets opened</em></p> <p><em>but during run time hen i click a link to open the same view file i get the above error</em></p> <p><em>this is the url</em></p> <p><em>whts going wrong </em></p> <pre class="brush: html">&lt;a href=&#34;@Url.Action(&#34;InfoAdd&#34;, &#34;Info&#34;)&#34;&gt;&lt;strong&gt;Add Information&lt;/strong&gt;&lt;/a&gt;</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/770932/Using-UrlAction-method-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/770932/Using-UrlAction-method-in-ASPNet-MVC/Fri, 27 Oct 2017 02:11:21 GMT