asp.net-mvc-5

ModelState is coming up as invalid?

扶醉桌前 提交于 2019-12-22 12:38:08
问题 I'm working on a MVC5 Code-First application. On one Model's Edit() view I have included [Create] buttons to add new values to other models from within the Edit() view and then repopulate the new value within DropDownFors() on the Edit() . For this first attempt, I am passing a model_description via AJAX to my controller method createNewModel() : [HttpPost] public JsonResult createNewModel(INV_Models model) { // model.model_description is passed in via AJAX -- Ex. 411 model.created_date =

Why is owin middleware created a second time after the HttpRequest ended

痴心易碎 提交于 2019-12-22 12:32:40
问题 After a question as per why the ApplicationDbContext from Asp.Net Identity is created and disposed twice per Request I did some research why this would happen. I found that the ApplicationDbContext is actualy created once per HttpRequest but when using the Owin pipeline the Owin Middleware will be created a second time after the HttpRequest has ended. Because of this the ApplicationDbContext is indeed created for a second time when a user clicks one link giving the impression that the object

Adding extra step to ASP.NET MVC authentication

橙三吉。 提交于 2019-12-22 11:29:19
问题 I have an MVC 5 website running using standard forms authentication. However I need to add an extra step to the user's login process. Once the user has been authenticated we look up whether or not they have access to multiple offices. If they do we need to show them a list of offices and they must choose one. This is a mandatory step and they cannot be considered logged on until they do it. Do we need to create our own authentication or should I add a check to a BaseController? 回答1: You can

ASP.Net MVC 5 Load list data via ajax

喜你入骨 提交于 2019-12-22 10:33:57
问题 I have a list in asp.net mvc 5 I have limited the number of records to be displayed in page. now on scroll I do ajax call, the first call works fine but when I scroll down more it recall the function repeatedly 5 to 10 times and lost it again display the data, it was really strange, I could not find solution My Controller: public ActionResult Index() { int starting = 0; if (Request.Form["starting"] != null) { starting = Convert.ToInt32(Request.Form["starting"]); } int takes = 15; if (Request

MVC @model meaning

情到浓时终转凉″ 提交于 2019-12-22 09:38:05
问题 in MVC5 , what does @model , @html and @using mean, why and when we usually use ( @ ) and which word follow it ? For example : @model MVC_Project2.Models.stufftable is written in the first of re.cshtml page stufftable is a table which is belong to users to create new user and the following code is written in the same page to create two textbox with two labels two labels to show the login page : @using (Html.BeginForm()) { <div> @Html.LabelFor(u => u.stuffname) @Html.TextBoxFor(u => u

Where can I load the user information to the session in ASP.NET MVC 5 with windows authentication?

我怕爱的太早我们不能终老 提交于 2019-12-22 08:04:31
问题 I want to use the ASP.NET MVC 5 for my web app. I need use the windows authentication . If I use the windows authentication where is the best place for reading user information (userid and roles) and store its to the Session ? I have the method for getting the user information by username from the database like this: public class CurrentUser { public int UserId { get; set; } public string UserName { get; set; } public Roles Roles { get; set; } } public enum Roles { Administrator, Editor,

HtmlAttributes in Extension Method

梦想的初衷 提交于 2019-12-22 07:12:40
问题 I'm using MVC 5 and I'm trying to write some Bootstrap extention methods. My goal is to 'overwrite' the Html.ActionLink method with Html.BootstrapLinkButton . The BootstrapLinkButton method should generate a link with the css classes "btn btn-default" automatically attached. My code so far: public static MvcHtmlString BootstrapLinkButton(this HtmlHelper htmlHelper, string linkText,string actionName, string controllerName, object routeValues = null, object htmlAttributes = null) { var

The type IUserStore`1 does not have an accessible constructor

谁都会走 提交于 2019-12-22 06:52:19
问题 I want to setup MVC5 application with Unity 3. I created a default web mvc5 application from a standard template then add unity When I am accessing the Register action in AccountController I get the following exception: The type IUserStore`1 does not have an accessible constructor. from this post How to add MVC 5 authentication to Unity IoC? I know the problem is that Unity selects the constructor with longer parameter list. The solution is to register the Account controller to be used with

Entity type has no key defined EF6

邮差的信 提交于 2019-12-22 06:47:31
问题 Here is my code although I already have refined the key attribute but still there is a problem. public class Contacts { [Key] public int ContactId { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } [DataType(DataType.EmailAddress)] public string Email { get; set; } } The error I get is: Entity Type 'Contacts' has no key defined. Define the key for this entity type

Custom Asp.net mvc 5 authentication without using Microsoft.AspNet.Identity.EntityFramework

安稳与你 提交于 2019-12-22 05:33:28
问题 How do you create a custom ASP.NET MVC 5 Auth without using the UserStore of Microsoft.AspNet.Identity.EntityFramework?? 回答1: All you have to do is implement the same interfaces that the Userstore for Identity.Entityframework uses. User will be your user class public class MyUserStore<TUser> : IUserLoginStore<TUser, int>, IUserClaimStore<TUser, int>, IUserRoleStore<TUser, int>, IUserPasswordStore<TUser, int>, IUserSecurityStampStore<TUser, int>, IUserStore<TUser, int>, IDisposable where TUser