Tag: asp.net mvc 5

GitHub提交错误:权限被拒绝致命:无法处理路径〜/ App_Data / aspnet-MyProject.mdf

我试图使用Microsoft Visual Studio 2017中的GitHub集成提交我的ASP.Net MVC项目的更新。 我正在开发Code-First Migrations。 在我上次成功提交之后,我在Visual Studio中的程序包管理器控制台上执行了以下命令: PM> Enable-Migrations -ContextType ApplicationDbContext PM> Add-Migration AccountNumberChanges PM> Update-Database -Verbose 完成后,我尝试执行提交,但是我收到以下错误: Git failed with a fatal error. error: open(“MyProject/App_Data/aspnet-MyProject- 20171110110346.mdf”): Permission denied fatal: Unable to process path MyProject/App_Data/aspnet- MyProject-20171110110346.mdf 上面的命令已将.mdf文件添加到项目的App_Data文件夹中。

我是如何做的如果在MVC5中通过函数validation

如果电子邮件存在function检查我想显示错误 我怎么做的? [RequiredIf(BL.datafuncs.checkIfExist(email) == true, ErrorMessage = “email already exist”)] public string email { get; set; }

ASP.NET MVC 5从特定角色获取用户

如何显示特定角色中所有用户的列表。 我将IdentityRole模型附加到我的View,并为其分配了“Admin”角色。 到目前为止我只能得到UserId。 @model Microsoft.AspNet.Identity.EntityFramework.IdentityRole @Html.DisplayNameFor(model => model.Name) // Shows ‘Admin’ @foreach (var item in Model.Users) { @Html.DisplayFor(modelItem => item.UserId) } 一种可能的解决方案是在控制器中创建用户列表并将其附加到视图。 问题是我还需要角色本身的数据。

C#5中不提供“插值字符串”function。请使用语言版本6或更高版本。

当我放入Razor View时,以下行不会编译。 var extPropLookupNameCompania = $”extension_{SettingsHelper.ClientId.Replace(“-“, “”)}_{“Compania”}”; 但是在控制器中,同一条线的工作完全正常。 为什么我不能在剃刀视图上进行用户字符串插值? 或者我可能需要配置一些东西?

关于MVC和身份的两个问题

我是身份和MVC的新手,我正在尝试创建一个MVC应用程序作为我的第一个项目之一。 我已经能够遵循一些教程并成功地向我的ApplicationUser添加了其他属性:IdentityUser类 public class ApplicationUser : IdentityUser { [Required] [Display(Name = “UserName”)] [StringLength(50)] public string Handle { get; set; } [StringLength(100, ErrorMessage = “Your {0} can be at most {1} characters long.”)] [Display(Name = “First Name”)] public string FirstName { get; set; } [StringLength(100, ErrorMessage = “Your {0} can be at most {1} characters long.”)] […]

MVC5使用MvcSiteMapProvider构建twitter bootstrap菜单

MVC5模板中的默认菜单部分如下所示: @Html.ActionLink(“Home”, “Index”, “Home”) @Html.ActionLink(“About”, “About”, “Home”) @Html.ActionLink(“Contact”, “Contact”, “Home”) @Html.Partial(“_LoginPartial”) _LoginPartial看起来像这样: @using Microsoft.AspNet.Identity @if (Request.IsAuthenticated) { using (Html.BeginForm(“LogOff”, “Account”, FormMethod.Post, new { id = “logoutForm”, @class = “navbar-right” })) { @Html.AntiForgeryToken() @Html.ActionLink(“Hello ” + User.Identity.GetUserName() + “!”, “Manage”, “Account”, routeValues: null, htmlAttributes: new { title = “Manage” }) Log off } } else { […]

Asp MVC:如何从ApplicationUser获取角色

在ASP.NET MVC 5中,在控制器中,我已经使用已发出请求的用户: ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); 使用ApplicationUser实例,我如何获得用户的所有角色?

单击时在主视图中加载局部视图

当用户单击链接时,我正在尝试获取部分视图以加载当前视图,但它会继续加载部分视图,而不是加载到同一视图上。 不知道我错过了什么。 主视图控制器 public PartialViewResult MonitorDetail(MonitorType mType) { return PartialView(“MonitorDetail”, mType); } 主视图 @Ajax.ActionLink(“SQL Cluster Online “, “MonitorDetail”, “NOCCon”, MonitorType.AHSSQLCluster, new AjaxOptions() { UpdateTargetId = “monitorDetail” }) @(Model.SQLClusterOnline ? “Online” : “Offline”) 部分视图 @model PAL.Intranet.MonitorType You choose @Model.ToString() 还告诉我mType是null但是我在ActionLink中传递它是MonitorType所以我把它添加为可空的所以我可以尝试找出第一个问题然后继续处理第二个问题。

路径控制器…未找到或未实现IController

我正在使用c#编写使用ASP.NET MVC 5的应用程序。 我需要在应用程序的右上角添加一个全局菜单。 我被告知其他SO使用ChildActionOnly属性的动作。 所以这就是我所做的。 我创建了一个像这样的BaseController public class BaseController : Controller { [ChildActionOnly] public ActionResult ClientsMenu() { using (SomeContext db = new SomeContext()) { return PartialView(db.Database.SqlQuery(“SELECT * FROM clients”).ToList()); } } } 然后我inheritance了BaseController所有控制器,就像这样 public class TasksController : BaseController { public ActionResult Index(int ClientId) { … return View(); } public ActionResult Show(int SurveyId) { … […]

用于在MVC5中模拟ConfirmEmailAsync和其他UserManager方法的接口

我正在尝试对这种控制器方法进行unit testing,该方法在当前的MVC项目中开箱即用。 [AllowAnonymous] public async Task ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return View(“Error”); } var result = await UserManager.ConfirmEmailAsync(userId, code); return View(result.Succeeded ? “ConfirmEmail” : “Error”); } AccountController有一个构造函数,它将ApplicationUserManager和ApplicationSignInManager作为参数,以及与私有setter匹配的属性用于测试。 但是,我无法弄清楚如何模拟ConfirmEmailAsync方法。 您可以在Identity命名空间中模拟各种接口: var store = new Mock<IUserStore>(); store.As<IUserEmailStore>() .Setup(x => x.FindByIdAsync(“username1”)) .ReturnsAsync((ApplicationUser)null); var mockManager = new ApplicationUserManager(store.Object); AccountController […]