Posts

Showing posts with the label asp.net-mvc

How does OnValidateIdentity ASP.NET Identity work

Image
Clash Royale CLAN TAG #URR8PPP How does OnValidateIdentity ASP.NET Identity work I'm trying to understand better how .NET's Identity OnValidateIdentity method works exactly. I have set up this piece of code in my application like following: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), CookieName = "LoginCookie", ExpireTimeSpan = TimeSpan.FromHours(1), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when the user logs in. // This is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromH...

How to post a WebGrid to a Controller using Ajax

Image
Clash Royale CLAN TAG #URR8PPP How to post a WebGrid to a Controller using Ajax I want to post the full WebGrid from my view to my controller using ajax. In this WebGrid I display a table from a database and I want to provide, that the user of this webpage can update the columns (in the database). WebGrid WebGrid My try so far: public JsonResult UpdateTable(GridView model) { // Update Model to db.. string message = "Success"; return Json(message, JsonRequestBehavior.AllowGet); } The GridView model here has always 0 columns. GridView model WebGrid <div id="tableGridDiv"> @grid.GetHtml( tableStyle: "table", columns: cols) </div> Script $('.save-user').on('click', function () { var grid = $("#tableGridDiv").find("table.grid").first(); alert(grid.innerHTML); var jsonGrid = JSON.stringify(grid); //var jsonGrid = $.parseJSON(grid); alert(jsonGrid); $.ajax({ ur...

How to populate dropdownlist inside Modal popup with dynamic data in MVC?

Image
Clash Royale CLAN TAG #URR8PPP How to populate dropdownlist inside Modal popup with dynamic data in MVC? I want to populate dropdownlist inside Modal popup with dynamic data in MVC. When I clicked on Open the DisplayModal modal should display with updated data in dropdowmlist. My Jquery code is not displaying Modal popup with new data in dropdownlist. Controller Open DisplayModal Jquery public PartialViewResult _ModalPopup(EmpViewModel model, string Id) { if (Id==null) { var Listdata = context.Employees.Where(x => x.id == "1").Select(y => y.Category).Distinct().ToList(); model.CategoriesList = new SelectList(Listdata); } else { var Listdata = context.Employees.Where(x => x.id == Id).Select(y => y.Category).Distinct().ToList(); model.CategoriesList = new SelectList(Listdata); } return PartialView("_MEmpModal", model); } View ...

How to populate data on nav-tab in partial View in MVC?

Image
Clash Royale CLAN TAG #URR8PPP How to populate data on nav-tab in partial View in MVC? I have partial View where I have 2 nav-tab. On Each tab, I want to populate data based on Country. Currently, I am getting following error: Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space. Controller public ActionResult Index() { ClsHome model = new ClsHome(); return View(model); } public PartialViewResult EmployeeBasedCountry(int CountryId) { ClsHome clshome=new ClsHome(); clshome.Country = CountryId; clshome.countries = CountryFilter(CountryId); return PartialView("~/Views/Home/_pEmp.cshtml", clshome); } Index View @model EmpWebsite.Models.Home.ClsHome <div class="col-md-5"> @Html.Partial("_pEmp...

ASP.NET MVC jQuery Unobtrusive Validation to compare between two dates

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET MVC jQuery Unobtrusive Validation to compare between two dates I'm trying to validate StartDate and EndDate using System.ComponentModel.DataAnnotations , such that the End Date must not be lesser than the Start Date. In my Model, I have defined the dates as follows: StartDate EndDate System.ComponentModel.DataAnnotations public partial class MyModel { [Required] public DateTime StartDate { get; set; } [Required] public DateTime EndDate { get; set; } } And I have also created a View Model as follows: public class CompareDateVM : IValidatableObject { public MyModel myModel { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if (myModel.EndDate < myModel.StartDate) { yield return new ValidationResult(errorMessage: "End Date cannot be lesser than Start Date.", memberNames: new { "EndD...

ASPNET Core MVC - Form to GET url

Image
Clash Royale CLAN TAG #URR8PPP ASPNET Core MVC - Form to GET url Good evening, I have a simple question that I can't seem to find answer to anywhere. I have a controller method with HttpGet route set like this: [HttpGet("tools/browse/{table}/{row}/{offset}")] My question is simple and I know that a lot of people would be interested in the answer aswell. How does one use such form: <form action="/tools/browse/{table}/{row}/{offset}" method="get"> <input type="text" name="table" value="" /> <input type="number" name="row" value="" /> <input type="number" name="offset" value="" /> <input type="submit" /> </form> ..so that {table}, {row} and {offset} contain values from the form itself? I know that the workaround would be using post or simply parsing the form data within function - b...

Custom Controller, not working with areas

Image
Clash Royale CLAN TAG #URR8PPP Custom Controller, not working with areas I have a custom controller in my project because I use Structure Map as an IOC Container. When I add Datatables.mvc (library for jquery grid), and call a view from areas, the custom Controller does not work at runtime and gives me an error. When I remove the Datatables.mvc from references, the project compiles successfully and renders the view form controller as well. public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); setDbInitializer(); //Set current Controller factory as StructureMapControllerFactory ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory()); Microsoft.AspNet.Signal...

MSbuild error in ASP.NET MVC

Image
Clash Royale CLAN TAG #URR8PPP MSbuild error in ASP.NET MVC I have a solution with 5 projects: This project had been building correctly until I update VS. After updated VS, I cannot rebuild or build the project. I try lots of ways for solving it but not working. I took a picture of error list and attached below. Error List Window By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Show element by checking session in asp.net

Image
Clash Royale CLAN TAG #URR8PPP Show element by checking session in asp.net I want to show element (div element) by checking Session of user It means if User didn't login when Click on the TextArea show Login page with Here is my code... <script> $(document).ready(function () { $('.form-control').click(function () { $('.form').show(); return false; }); }); </script> ///code of textarea <div class="form-group"> <textarea class="form-control" name="Text" id="Text" rows="5" data-rule="required" placeholder="message" onclick="loginfunction"></textarea> <input type="hidden" name="Date" id="Date" class="form-control" value="@DateTime.Now" /> <div class="validation"></d...

The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'

Image
Clash Royale CLAN TAG #URR8PPP The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' Trying to teach myself some new tools, but I've managed to break my project. The solution is about a day old and consists of two projects. One is the application (created using the Visual Studio .NET Core 2.1 SDK + React Template ), and the other is the data layer (which is just a Models folder). Models The data layer was implemented today, and that's when things got rocky. I don't want to point the finger there immediately, because it could've happened with some other changes I was making at the same time. One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false. The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missi...

ASP.NET Core 2.1 MVC - Model Binding - Dropdown List Value

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET Core 2.1 MVC - Model Binding - Dropdown List Value I have a ViewModel something like this which contains two properties. UserSelectedState - String value ListOfStateNames - This is a List of SelectListItem. I am able to bind the model to the View and the user sees the list of state names and makes one selection. I am posting it back to the controller and I am able to see the "UserSelectedState" value assigned correctly. But, the "ListofStateNames" is empty in the Model when posted back. Just trying to understand why it should be empty. Since it's the same Model which is populating the list items in the View. Any explanation on why it is empty ? 1 Answer 1 This is just how html POST works. On a roundtrip only values of certain types are returned: input, hidden field, selected option. Where readonly fields, labels, etc. are not returned. S...

I can't find TempData in System.web.mvc

Image
Clash Royale CLAN TAG #URR8PPP I can't find TempData in System.web.mvc as the tittle i can't find TempData in System.Web.mvc. Here is the picture https://imgur.com/a/YwvLY0A For more information, I deleted some references due to not-working open source like CKeditor,.. I am wondering if I deleted somthing important and how to check it. Thanks for your support By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How do I implement search to happen across pages without making a call to the DB in MVC?

Image
Clash Royale CLAN TAG #URR8PPP How do I implement search to happen across pages without making a call to the DB in MVC? I have a search function that works fine,, but only for the first page. I have implemented the pagination concept in my application. Here's my search function: function Search() { var se = $('#SearchGrid').val().toUpperCase(); var i, td; debugger; var x = document.getElementById("VolunteerGrid"); var tr = x.getElementsByTagName("tr"); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[0]; if (td) { if (td.innerHTML.toUpperCase().indexOf(se) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } I want this search function to get all the rows and not just the rows on the first page and show the result. Here's my simple view: ...

Ajax callback is firing after function call

Image
Clash Royale CLAN TAG #URR8PPP Ajax callback is firing after function call Hi Have a ajax call in a function thats called on date input change event to check if a date is already in use for User. the success in the Ajax call fires after the click function is finished. How do I get the success results and continue on with the #datepicker change funtion as I need the json results for rest of function. controller public ActionResult IsDateAvailable(DateTime date, int Id) { var dateAvailable = !(_context.Trading.Any(t => t.uId == Id && t.TradingDate == date)); if (!(dateAvailable)) { return Json(new { status = false, msg = "This date already exists." }); } return Json(new { status = true }); } JavaScript $(document).ready(function() { var message; var isDateValid; function CheckDate(para) { var dateValid; var mesg; return $.ajax({ url: '@Url.Action("IsDateAvailable", "Trading")', type...

routing in iis 8.5 for mvc and webapi apps

Image
Clash Royale CLAN TAG #URR8PPP routing in iis 8.5 for mvc and webapi apps I am running windows 8 IIS 8.5. I created my site on IIS and created another site in a directory below for my webapi service So my site looks like this: www.mysite.com www.mysite.com/api // this exists on disk in a directory called api below the site dir. Configured in IIS as a site not a virtual dir. Of course iis is unable to implement routing for either site. ww.mysite.com works if I add /index.html. If I type www.mysite.com into browser I get a 404. The api site simply gives me 404 errors no matter what I do. Both sites work perfectly fine when running in visual studio. www.mysite.com is a mvc 5 application www.mysite.com/api is a webapi 3 application. Some questions such as this one: ASP.NET 4.5 MVC 4 not working on Windows Server 2008 IIS 7 recommend <modules runAllManagedModulesForAllRequests="true" /> which does not work and is suboptimal even if it did work. Other problems others hav...

Get the less-sold items with LINQ

Get the less-sold items with LINQ I have 2 objects (Order and Product) and a third (OrderDetail) that will be used as "navigation" between Products and Orders. I'm trying to build a view that will show the less-sold products. For that I am "querying" the object OrderDetail and saving the result in a view model to later on be used in the view. Model: public class Product { public int ProductID { get; set; } public string CodProduct { get; set; } public string Nome { get; set; } (...) public ICollection<OrderDetail> OrderDetails { get; set; } } public class Order { public int OrderID { get; set; } (...) [BindNever] public ICollection<OrderDetail> OrderDetails { get; set; } } public class OrderDetail { public int OrderDetailId { get; set; } public int OrderId { get; set; } public int ProductID { get; set; } public int Quantity { get; set; } public decimal UnitPrice { get; set; } public virtual Product Product { get; set; } ...