asp.net-mvc-5

ASP MVC 5 Attribute routing VS. Convention-based routing

扶醉桌前 提交于 2019-12-03 09:36:19
问题 ASP MVC 5 has a new Routing called attribute routing. The way I see it, the routes are now scattered on every controller unlike with the convention-based that there is single location RouteConfig.cs where you can check your routes, which also serves as documentation of your sites routes in some way. My question is it better to use Attribute routing over the convention-based routing in terms of readability and maintainability? And can someone suggest how to design routes for better

Is “jquery.unobtrusive-ajax.js” obsolete?

半腔热情 提交于 2019-12-03 09:26:39
I have an ancient MVC2 solution that I migrated to MVC5 (Visual Studio 2013). I'd like to update the old libraries used in the project with the new ones. I have by eg. the jquery.unobtrusive-ajax.js library. Is it obsolete as by now? I ask because that library references /// <reference path="jquery-1.4.4.js" /> but I upgraded the jQuery (I use the jQuery v1.8.3 by now). If it with what to replace (like jquery.validate.unobtrusive.js (?)) PS. In a default MVC project Visual Studio 2013 proposes the folowing "validation" scripts: jquery.validate-vsdoc.js jquery.validate.js jquery.validate.min.js

How can I use placeholder attribute with Html.EditorFor?

时间秒杀一切 提交于 2019-12-03 09:21:42
I want to use the placeholder attribute in the Html.EditorFor so I did just like in the first answer: Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? But in the final part, I don't have the EditorTemplates folder so I created it and when I tried to create the string.cshtml view I couldn't because the name "string" is reserved so I chose stringg.cshtml instead and it didn't work! Do I have to change the name elsewhere in my program? I did exactly like the answer... Thank you! Medo Upgrade to MVC 5.1 and you can use HTML attributes in EditorFor: @Html.EditorFor(m => m.variable, new

MVC5 view drop down list

天大地大妈咪最大 提交于 2019-12-03 09:03:19
In a C# MVC5 Internet application view, how can I display a dropdown list for a user to select a list item that is populated from a View Model list? Here is the ViewModel code: public class MapLocationItemViewModel { [Editable(false)] public int mapLocationForeignKeyId { get; set; } public List<string> mapLocationItemTypes { get; set; } public MapLocationItem mapLocationItem { get; set; } } Here is the code that I currently have in the View : <div class="form-group"> @Html.LabelFor(model => model.mapLocationItem.mapLocationItemType, new { @class = "control-label col-md-2" }) <div class="col-md

MVC 5 Role Based Authentication

自闭症网瘾萝莉.ら 提交于 2019-12-03 08:59:19
I am trying to lock down our "admin" page to only admins using Asp.net Identity (we are building in MVC5). I can get [Authorize(Users="admin")] to work but can not get [Authorize(Roles="Admin")] to work. I have created the role in the dbo.AspNetRoles table and then associated the account in the AspNetUserRoles by pairing the user GUID to the ID in the aspnetroles table. I have seen in previous editions of MVC you have had to get into web.config to add some lines. Can anyone help point me in the right direction? Have you specified in the web.config that you are going to use roles? <roleManager

Role Management in ASP MVC 5 (Microsoft.AspNet.Identity)

余生颓废 提交于 2019-12-03 08:53:26
in ASP MVC5 RC I didn't get the role system to work. My database has all needs tables an role exist but proofing if user is in role always return false (no SQL exception or something)!? Did I need to activate role system for IPrincipal somewhere? Test code: AccountController accCont = new AccountController(); // check role exist : result = true var roleExist = await accCont.IdentityManager.Roles.RoleExistsAsync("61c84919-72e2-4114-9520-83a3e5f09de1"); // try find role by name : result = role object var role = await accCont.IdentityManager.Roles.FindRoleByNameAsync("ProjectAdministrator"); //

Updating user role using asp.net identity

荒凉一梦 提交于 2019-12-03 08:39:43
I have the following problem. While using the following code below to change the user's current role i am getting an exception with the message like below: [HttpPost] [ValidateAntiForgeryToken] public virtual ActionResult Edit(User user, string role) { if (ModelState.IsValid) { var oldUser = DB.Users.SingleOrDefault(u => u.Id == user.Id); var oldRoleId = oldUser.Roles.SingleOrDefault().RoleId; var oldRoleName = DB.Roles.SingleOrDefault(r => r.Id == oldRoleId).Name; if (oldRoleName != role) { Manager.RemoveFromRole(user.Id, oldRoleName); Manager.AddToRole(user.Id, role); } DB.Entry(user).State

How to map Entity Framework model classes with Business Layer class in n-tier architecture - ASP.NET-MVC

隐身守侯 提交于 2019-12-03 08:31:48
I am working on e-tier architecture within MVC framework (ASP.NET MVC5, Entity Framework 6). My application is divided into three sub-projects which are Business-Layer, Data-Access-Layer, Repository (This include repository and Unit of Work) and ASP.NET MVC web-app. I am struggling to understand mapping between business data and entity framework model. for example if I have model class User in entity framework as DAL - User Model [Table("User")] public class User { public User() { } [Key] public int UserID { get; set; } [StringLength(250)] [Required] public string FirstName { get; set; }

Nuget dependency error installing RavenDb Embedded

梦想与她 提交于 2019-12-03 08:19:43
问题 I am trying to install RavenDB.Embedded in an ASP.NET MVC 5 application, but I have this dependency error: PM> Install-Package RavenDB.Embedded Attempting to resolve dependency 'RavenDB.Database (= 2.5.2750)'. Attempting to resolve dependency 'System.Spatial (≥ 5.2)'. Attempting to resolve dependency 'WindowsAzure.Storage (≥ 2.0)'. Attempting to resolve dependency 'Microsoft.WindowsAzure.ConfigurationManager (≥ 1.7.0.0)'. Attempting to resolve dependency 'Microsoft.Data.OData (≥ 5.0.2)'.

Email confirmation in ASP.NET mvc5 without sendgrid

无人久伴 提交于 2019-12-03 07:58:29
问题 The title pretty much says it. Is there a way of adding Email Confirmation to my application without using the send grid ? my Azure account won't let me use it, says it isnt available in my zone and i cant seem to find another solution . 回答1: I didn't use sendgrid neither in my website for the Email confirmation service. I See no point having it in small websites with low traffic. I use gmail SMTP service instead and it's works perfectly: using System; using System.Collections.Generic; using