asp.net-mvc-5

Result of LINQ Query in MVC SelectList as Value and Text - not working

我是研究僧i 提交于 2019-12-22 05:29:11
问题 I am trying to use the result of a LINQ Query to populate a SelectList in a MVC 5 application. The LINQ query returns customer IDs. Model public partial class Pricelist { public int CustomerID { get; set; } public int SelectedCustomer { get; set; } public Pricelist(int customerID, int selectedCustomer) { } } View @Html.DropDownList("custList") Controller (1) var query = ((from s in db.Pricelists select s.CustId).Distinct()).ToList(); int i = 1; List<Pricelist> CustomerList = new List

cookie not being set when Expires less than 1 year, on localhost (Chrome and FF)

感情迁移 提交于 2019-12-22 05:26:34
问题 I'm facing a problem on localhost, and in Chrome and Firefox , not Edge this code will work ok, and will set the cookie: [HttpPost] public ActionResult Change(string val) { var cookie = new HttpCookie(CookieName) { Value = val, Expires = DateTime.Now.AddYears(1) }; Response.Cookies.Add(cookie); return Content(""); } however if I change the Expires to just 300 days , the cookie won't be sent back in the Request Cookies , (it will still be visible in the Response Cookies for the Change request)

Error:Upgrade MVC4 to MVC5 in VS2012

早过忘川 提交于 2019-12-22 05:25:35
问题 I am getting below error after upgrade my project from MVC4 to MVC5. I followed How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 Assembly 'WebServices.WebApi.External, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' How to solve

ASP.NET MVC 5 Model-Binding Edit View

狂风中的少年 提交于 2019-12-22 05:25:11
问题 I cannot come up with a solution to a problem that's best described verbally and with a little code. I am using VS 2013, MVC 5, and EF6 code-first; I am also using the MvcControllerWithContext scaffold, which generates a controller and views that support CRUD operations. Simply, I have a simple model that contains a CreatedDate value: public class WarrantyModel { [Key] public int Id { get; set; } public string Description { get; set; } DateTime CreatedDate { get; set; } DateTime

Do WebApi 2 and MVC 5 user different routing attributes?

↘锁芯ラ 提交于 2019-12-22 05:16:31
问题 Reading through this blog post on attribute routing in ASP.NET MVC 5 and this one on attribute routing in Web Api 2, it looks like there are two sets of routing attributes, one in the System.Web.Mvc namespace and the other in System.Web.Http . Is that right and does anyone have any idea (links) as to why it was designed this way? Should one be used over the other or are they supposed to live side by side? 回答1: Yes, these route attributes are intentionally different since Web API and MVC have

How to pass a list of id's in a AJAX request to the Server in MVC

混江龙づ霸主 提交于 2019-12-22 05:05:01
问题 In a AJAX request to the server in MVC, how can I pass a list of id's to the controller's action function? I accept with or without use of Html helpers. I know MVC's model binder has no problem when it comes to simple types like int , string and bool . Is it something like I have to use and array instead in the action? I don't care if I have to use an array or List and even if the strings I int or strings I can always convert them. I just need them on the server. My List ids gives null at the

MVC 5 Redirect to Login Page Not Working with OWIN

血红的双手。 提交于 2019-12-22 05:03:54
问题 I'm trying to get my head around using OWIN. I have created two MVC 5 projects. One with authentication using Aspnet.Identity and the other started as an empty project. I added the following to the emptyp project: Account controller with a Login action and coresponding view Startup.cs and another partial Startup.cs with public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType =

How to redirect to route using custom attribute routing in MVC5

▼魔方 西西 提交于 2019-12-22 04:46:08
问题 I'm not sure if what I'm attempting to do is valid as I'm a relative newbie to the C# / ASP.NET / MVC stack. I have a controller action like this in ModelController.cs //Get [Route("{vehiclemake}/models", Name = "NiceUrlForVehicleMakeLookup")] public async Task<ActionResult> Index(string vehicleMake) { // Code removed for readaility models = await db.VehicleModels.Where(make => make.VehicleMake.Make == vehicleMake).ToListAsync(); return View(models); } and in another controller called

Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult

不问归期 提交于 2019-12-22 04:40:23
问题 I've set up this test method on a controller to strip out any complication to it. Based off of all the results I've found from searching this should work. I'm not sure what I'm missing here. public JsonResult test() { return Json(new { id = 1 }); } This is the error I get. Cannot implicitly convert type 'System.Web.Http.Results.JsonResult' to 'System.Web.Mvc.JsonResult' 回答1: you should return a JsonResult instead of just Json public JsonResult test() { var result = new JsonResult(); result

What is the difference between using AuthorizeAttribute or IAuthorizationFilter?

强颜欢笑 提交于 2019-12-22 04:31:32
问题 AuthorizeAttribute requires you to override the OnAuthorization method and IAuthorizationFilter requires you to implement an OnAuthorization method. Seems like the same thing to me, are there any other differences? Why would one be used over the other? EDIT: To clarify, I'm trying to understand what the difference is between the following 2 pieces of code. public class PasswordExpirationCheckAttribute : AuthorizeAttribute { private int _maxPasswordAgeInDays; public