Tag: asp.net mvc 4

在覆盖成员时注册了抛出的inheritance安全规则

对于我的学校项目,我使用的是MVC项目附带的默认Account Controller注册函数: // POST: /Account/Register [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Register(RegisterViewModel model){ if (ModelState.IsValid){ var user = new ApplicationUser(){UserName = model.UserName}; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded){ await SignInAsync(user, isPersistent: false); return RedirectToAction(“Index”, “Home”); } else{ AddErrors(result); } } // If we got this far, something failed, redisplay form return View(model); } […]

为什么找不到我的BasicAuthenticationModule?

我正在尝试创建自己的基本身份validation实现。 我将BasicAuthenticationModule.cs存储在我的solution\Modules ,其名称空间为: namespace Web_API.Modules { public class BasicAuthenticationModule2 : IHttpModule 我已将它添加到我的web.config中: 运行这个让我: HTTP Error 500.19 – Internal Server Error – Cannot add duplicate collection entry of type ‘add’ with unique key attribute ‘name’ set to ‘BasicAuthenticationModule’ 有人有线索吗?

ModelBindervalidation使用reflection在getter上中断

我遇到了一个似乎与reflection和模型绑定器validation有关的问题,特别是FormatterParameterBinding.ExecuteBindingAsync(..) ,虽然我可以使用一个方法来做我想要的但如果我可以使用我会更喜欢它财产。 在这里,我正在寻找对模型绑定器validation过程的一些见解,为什么我无法做我想做的事情以及如何解决问题,或者解决它。 设置 public class ModelBindingValidationBreaker { public ModelBindingValidationBreaker() { Properties = new List(); } public int A { get; set; } public int B { get; set; } public IList Properties { get; set; } /*// Uncomment to break the model binder validation! public IList PropertyInfos { get { return GetType() .GetProperties() .Where(pi […]

MVC4中表的Foreach循环

我正在使用c#在MVC4中完成我的项目。 我的模型中有一个IEnumerable列表。 我使用以下循环在我的视图中列出。 @foreach(var item in Model) { Rtn. @item.Mem_NA(@item.Mem_Occ) } 其实我想要输出如下表所示 Rtn.item.Mem_NA1(item.Mem_Occ1) Rtn.item.Mem_NA2(item.Mem_Occ2) Rtn.item.Mem_NA3(item.Mem_Occ3) Rtn.item.Mem_NA4(item.Mem_Occ4) Rtn.item.Mem_NA5(item.Mem_Occ5) Rtn.item.Mem_NA6(item.Mem_Occ6) 是否可以使用foreach循环生成上面的表格。 或者更好地使用div而不是table。 请帮我

错误:异步操作仍处于挂起状态时,异步模块或处理程序已完成

我有一个Controller Action方法来保存用户详细信息,如下所示。 public async Task SaveUser(ViewModel.VM_CreateUser user) { var result = await _user.Save(userDetails); return Json(new { Success = String.IsNullOrEmpty(result) }); } 到目前为止,上述4行function没有问题。 public async Task SaveUser(ViewModel.VM_CreateUser user) { var result = await _user.Save(userDetails); new MailController().CreateUser(user.userDetails); //<==This is problem line of code. } 以下是我的邮件控制器。 public class MailController : MailerBase { public void CreateUser(ViewModel.VM_User user) { To.Add(user.EmailAddress); […]

MVC错误“属于’System.Int32’类型,但必须是’IEnumerable ‘类型。 “

我有这样的模特; public int ID{ get; set; } public string MidName{ get; set; } public string FirstName{ get; set; } public string Surname{ get; set; } 这是我的控制器: public ActionResult Create(){ ViewBag.Names= new SelectList(db.TbName, “ID”, “MidName”); return Viwe(); } 这是我的观点 @Html.LabelFor(model => model.Names, new { @class = “control-label col-md-2” }) @Html.DropDownList(“Names”, String.Empty) @Html.ValidationMessageFor(model => model.Names) 现在,当单击“创建”按钮时,我收到错误消息 `具有键’Names’的ViewData项的类型为’System.Int32’,但必须是’IEnumerable’类型。 […]

Paypal Ipn与asp.net MVC集成

HomeControler / Index.cshtml页面如下 User ID Pay with PayPal HomeControler / Ipn Action方法如下 public ActionResult Ipn() { // Receive IPN request from PayPal and parse all the variables returned var formVals = new Dictionary(); formVals.Add(“cmd”, “_notify-validate”); // if you want to use the PayPal sandbox change this from false to true string response = GetPayPalResponse(formVals, false); […]

ASP.Net MVC应用程序中的线程安全全局变量

我需要在ASP.Net MVC应用程序中实现一个multithreading全局变量。 ConcurrentDictionary是理想的,但如何让我的应用程序中的每个用户会话都可以访问它? 这样的事情可以做到吗? public static class GlobalStore { public static ConcurrentDictionary GlobalVar { get; set; } } 我需要多个用户才能读取和写入此对象。

如何根据MVC中的下拉选择填充文本框..?

您好我已经创建了一个表并通过ADO.NET实体将其连接到MVC项目。 连接后,我为实体添加了控制器,并在MVC项目的VIEW文件夹中创建了一组cshtml文件。 但现在我需要的是创建一个下拉列表和文本框。 我在cshtml文件中创建了下拉列表,并且还在CONTROLLER中修改了它的逻辑。 我也可以创建TEXTBOXES,但是我面临着根据下拉列表选择对TEXTBOX进行打包的问题。 我的VS自动生成的模型是 public partial class Plan_S { public int PlanId_PK { get; set; } public string PlanNames { get; set; } public string Hours { get; set; } } 我的用于显示下拉列表的控制器是` public class dropdownController : Controller { private PivotEntities db = new PivotEntities(); // // GET: /dropdown/ public ActionResult Index() { ViewBag.plannames […]

entity framework分析器 – 带有EF 6的ASP.NET MVC4 – 无法确定提供者名称

我已经在我的ASP.NET MVC4项目中使用EF 6一段时间了,没有任何问题。 当我向项目添加Entity Framework Profiler时出现问题,然后我突然收到以下错误:“无法确定类型为’System.Data.SqlClient.SqlClientFactory’的提供程序工厂的提供程序名称。确保ADO。 NET提供程序已在应用程序配置中安装或注册。“ 我尝试了一些建议,包括bin文件夹中不存在“EntityFramework.SqlServer.dll”的问题。 堆栈跟踪: System.Data.Entity.Config.DefaultInvariantNameResolver.GetService(Type type, Object key) +440 System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +83 System.Data.Entity.Config.CachingDependencyResolver.GetService(Type type, Object key) +179 System.Linq.WhereSelectArrayIterator`2.MoveNext() +82 System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +215 System.Linq.WhereSelectArrayIterator`2.MoveNext() +82 System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +215 System.Data.Entity.Config.CompositeResolver`2.GetService(Type type, Object key) +71 System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService(IDbDependencyResolver resolver, Object key) +84 System.Data.Entity.Internal.InternalConnection.get_ProviderName() +112 System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context) +120 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +319 […]