Tag: asp.net mvc

不支持每种类型的多个对象集。 对象集IdentityUsers’和用户都可以包含类型的实例

对象集IdentityUsers’和用户都可以包含net类型的实例 但是我试图创建一个多对多的关系,比如这个教程显示了get-started-with-ef-using-mvc 但是我得到了这个错误=> Multiple object sets per type are not supported. The object sets ‘IdentityUsers’ and ‘Users’ can both contain instances of type ‘bugs_b_gone.Models.ApplicationUser’ Multiple object sets per type are not supported. The object sets ‘IdentityUsers’ and ‘Users’ can both contain instances of type ‘bugs_b_gone.Models.ApplicationUser’ 。 我在项目类中有一个属性,所以创建项目的用户是管理员但是现在管理员必须创建用户并将其分配给项目 public class Project { [Key] public int ProjectID […]

在ASP.NET MVC 5中将整个对象从视图传递到控制器

有没有办法将整个对象从ASP.NET MVC 5 View传递给Controller? 这是我的情况: 我有一个显示数据库表中所有行的视图 视图的模型是IEnumerable 每行都有一个链接,它的数据导致了scaffolded UPDATE视图 有没有办法将整个对象传递给Update控制器方法,以便它最初用旧数据填充表单输入? 就像是: @Html.Action(“Update me!”, “Update”, new { objectFromModelList }) 然后在控制器中 public ActionResult Update(MyType parameter) { return View(parameter); } 或类似的东西。 请帮助,我是新手,无法在任何地方找到答案。

.NET Core 2.1 HttpClient不返回预期值

我正在使用一个接口从这个URL调用api http:// localhost:55260 / api / Accounts / GetList 这是它引用的控制器: [HttpGet] [Route(“GetList”)] [AllowAnonymous] public ActionResult<IEnumerable> GetList() { return new string[] { “value1”, “value2” }; } 但是,而不是返回的字符串,我得到这个: 这就是我声明我的httpclient /接口的方式: private readonly HttpClient httpClient; public AuthenticationClient(HttpClient httpClient) { httpClient.BaseAddress = new Uri(“http://localhost:55260/api/Accounts”); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue(“application/json”)); this.httpClient = httpClient; } public async Task<IEnumerable> GetDataAsync() { List result […]

无效控制器时的StructureMap错误

我正在使用像Rob Conery那样的MVC店面的结构图,我有一个AdminController,所以我只需输入: website/Admin/action 但如果我拼错控制器名称,我会得到以下错误: exception详细信息:System.ArgumentNullException:值不能为null。 参数名称:key 此行发生错误: Controller controller = ObjectFactory.GetInstance(controllerType) as Controller; 有没有人对我如何处理这个错误有任何想法,或者根本不允许它发生,也许只是转到404页面? 提前干杯

“IEntityChangeTracker的多个实例无法引用实体对象”

我有3个数据库表:Vendors,Regions和VendorRegions: Vendors ——————- VendorID (PK) Name Regions ——————- RegionID (PK) Name VendorRegions ——————- VendorID (PK) RegionID (PK) 在我创建供应商的页面上,我列出了一个复选框列表中的每个Region。 对于每个检查的区域,我想将VendorID和RegionID添加到VendorRegions表。 我正在使用Entity Framework,C#和MVC 3。 这是我的控制器代码: public class VendorsController : Controller { readonly IVendorsRepository _vendorsRepository; readonly IRegionsRepository _regionsRepository; public VendorsController() { _vendorsRepository = new SqlVendorsRepository(); _regionsRepository = new SqlRegionsRepository(); } [HttpPost] public ActionResult Create(VendorViewModel viewModel, string[] Regions) { […]

将DataAnnotations添加到自动生成的DBML类? MVC 2.0 ASP.NET

我很担心这样做,因为我的更改将在dbml文件再次自动生成时被覆盖(通常是这样)。 我正在考虑做一个局部课并写出相同的属性来注释它们,但担心它会抱怨重复,我甚至无法进行实验的原因让我想到了我的问题的第二部分…… … …我的dbml文件列表中的可展开箭头丢失,右键单击并选择“查看代码”只显示一个空的分部类,如下所示… Partial Class FPDataContext End Class 所以,我甚至无法查看课程! 有人提出任何想法吗? 我正在使用VS2010 RC并且我正在开发一个MVC 2.0应用程序,我希望能够使用UI注释,例如[UIHint(“RelativeDateTime”)] 编辑: 问题解决了,谢谢史蒂夫,这里以我的VB版编辑为例…… Imports System.ComponentModel.DataAnnotations _ Partial Public Class Comment End Class Public Class CommentMetaData _ Public Property DateAdded() As DateTime End Class

claim-types中的URL是什么

由于我想在我的应用程序中添加自定义声明,因此我检查了ClaimTypes的源代码(使用JetBrains反编译器反编译)。 这是它的一部分: namespace System.Security.Claims { /// Defines constants for the well-known claim types that can be assigned to a subject. This class cannot be inherited. [ComVisible(false)] public static class ClaimTypes { internal const string ClaimTypeNamespace = “http://schemas.microsoft.com/ws/2008/06/identity/claims”; /// The URI for a claim that specifies the instant at which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant. public […]

为什么Nhibernate在我的MVC应用程序中跨多个请求共享会话?

我们有一个MVC项目,通过StructureMap构建NHibernate依赖项 var sessionFactory = ConnectionRegistry.CreateSessionFactory(); For().Singleton().Use(sessionFactory); For().Singleton().Use(); ConnectionRegistry.CreateSessionFactory看起来像这样 public static ISessionFactory CreateSessionFactory() where T : ICurrentSessionContext { if (_sessionFactory == null) { lock (_SyncLock) { if (_sessionFactory == null) { var cfg = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(DataFactory.ConnectionString)) .CurrentSessionContext() .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .ExposeConfiguration(c => c.SetProperty(“generate_statistics”, “true”)) .ExposeConfiguration(c => c.SetProperty(“sql_exception_converter”, typeof(SqlServerExceptionConverter).AssemblyQualifiedName)); try { _sessionFactory = cfg.BuildSessionFactory(); } catch (Exception […]

我应该通过RedirectToAction还是TempData传递值?

我已经看到一些文章(甚至MSDN)建议TempData在ActionMethods之间传递数据。 但我在这里看到其他人说TempData应该避免。 采用这种方法的最佳实践方法是什么? 这是一些显示我的情况的代码。 注意:我100%肯定,我做错了。 这就是我在这里的原因。 :)此外,我一直在做Webforms直到最近。 注2: 这是相关的,但不一样。 视图: @using (Html.BeginForm(“Previous”, “Home”, new {month = @month}, FormMethod.Post)) { } // This fails but that’s another situation @using (Html.BeginForm(“Next”, “Home”, new {month = @month, year = @year}, FormMethod.Post)) { } 控制器方法: [HttpPost] public ActionResult Previous(HTMLMVCCalendar.Models.MonthModel prevMonth) { Calendar monthEventsCal = new Calendar(); int month = […]

充分利用具有n(3)层架构的MVC Owin身份

我一直在学习开箱即用的Owin Identity ,我喜欢它为我们提供用户管理的易用性。 然后我遇到的问题是它通过ApplicationDbContext直接与EF(貌似)进行交互,这是我不想要的。 我更喜欢使用我的3层架构,IE它与服务层(BLL)交互,后者与EF交互。 我找不到模板,教程,甚至起点来维护所提供的所有function并实现我想要的分离。 那么有没有办法在MVC Identity包中使用服务层代替ApplicationDbContext 。