asp.net-mvc-5

pass a different model to the partial view

若如初见. 提交于 2019-11-30 11:17:03
I am trying to pass a different model to the partial view from a view. I have two separate controller actions for both of them and two different view models. But when I call the partial view from within the view it gives me the error The model item passed into the dictionary is of type 'Application.ViewModels.Model1ViewModel', but this dictionary requires a model item of type 'Application.ViewModels.PartialViewModel'. I am calling it like this: @Html.Partial("_CreateUniFunctionPartial") the model call in the view is @model Application.ViewModels.Model1ViewModel and model in partial view file

Clientside validation fails for date format dd/mm/yyyy in jQuery Validate

ぃ、小莉子 提交于 2019-11-30 10:11:39
I am using jQuery Validate plugin for clientside validation in an MVC 5 application. For the date fields cilentside validations fails when using dd/mm/yyyy format. Is there a way to change the date format in jQuery Validation? Adding to Darin's answer. If you happen to already be using the datepicker plugin from JQuery UI then you can use that date parser instead of creating your own: $.validator.methods.date = function (value, element) { return this.optional(element) || $.datepicker.parseDate('dd/mm/yy', value); } Darin Dimitrov You could override the date parsing method of the validate

MVC5 ApplicationUser custom properties

老子叫甜甜 提交于 2019-11-30 10:04:10
I am trying to get to grips with the new Membership system introduced in ASP.NET MVC 5 and I've come across a small issue which I am pretty sure you will be able to help me with. I am going based off this tutorial and have introduced custom properties to ApplicationUser such as Name, Surname, DOB, etc. However, instead of creating the user, I am trying to update the currently logged in one. I am looking at the controller method which is currently used to change password. public async Task<ActionResult> Manage(ManageUserViewModel model) { string userId = User.Identity.GetUserId(); bool

Why is UserManager.CreateIdentityAsync() looking for IdentityRole and how to fix?

五迷三道 提交于 2019-11-30 10:03:25
I'm using Identity2.0 with MVC5 CodeFirst I have extended both the IdentityUser and IdentityRole like this: public class ApplicationUser : IdentityUser { [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public string LastName { get; set; } } public class ApplicationRole : IdentityRole { [Required] [StringLength(50)] public string ProperName { get; set; } [Required] public string Description { get; set; } } public class MyAppDb : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim> {

Pushing values to javascript array returning lots of errors

怎甘沉沦 提交于 2019-11-30 10:00:16
问题 I'm tring to fill a javascript array with lat longs that I can use to put markers on a map from my model but it's riddled with errors and I'm not sure why. <div id="map"></div> <script> var map, points = []; @foreach (var a in Model) { //Error: The name 'points' does not exist in the current context //Error: ) expected ; expected (at front and end brackets) points.push({ lat: @a.Lat, lng: @a.Lon }); } function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {

MVC Remote Validation With Additional bool Fields

风流意气都作罢 提交于 2019-11-30 09:40:32
问题 I am trying to use Remote Validation with an additional bool checkbox field [Remote("IsStorageConnectionValid", "TenantManagement", AdditionalFields = "CreateStorage")] public String StorageConnectionString { get; set; } Validation code public JsonResult IsStorageConnectionValid(string storageConnectionString, bool createStorage){ It works perfectly in terms of it hitting the validator. However createStorage is always true irrespective of the value of the checkbox. If I use additional fields

MVC Contact Form with Email

丶灬走出姿态 提交于 2019-11-30 09:36:22
I wonder if someone can please help with a MVC Contact Form which send an Email on submission? I think I have most elements setup, but for some reason the form appear to be sending (takes ages) then just returns back to the form and no email is received. MailModels.cs: namespace WebApplication1.Models { public class MailModels { public string Name { get; set; } public string Email { get; set; } public string Telephone { get; set; } public string Message { get; set; } } } Contact.cshtml: @using (Html.BeginForm("Contact", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @id

MVC Identity 2 using FormsAuthenticationTicket

﹥>﹥吖頭↗ 提交于 2019-11-30 09:32:40
问题 I am replacing the (HttpContext.Current.User) IPrincipal with a custom version so I can store more information login and the user. I have done this before using the FormsAuthtenticationTicket, but those other ways were based on the Memberhipship and SimpleMembership providers. My question is, can i use the FormsAuthenticationTicket to store the cookie of my ICustomPrincipal with it interfering or breaking in OWIN Identity Pipline? I feel like would i be mixing apples and oranges. example save

MVC5 Account Controller null reference exception

孤街浪徒 提交于 2019-11-30 09:20:54
I am trying to implement user roles into my MVC web application. However I am getting a null exception on the line return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); in my account controller. Account Controller [Authorize] public class AccountController : Controller { private ApplicationSignInManager _signInManager; private ApplicationUserManager _userManager; private ApplicationRoleManager _roleManager; public AccountController(){} public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager,

Does ASP.NET Identity 2 support anonymous users?

ⅰ亾dé卋堺 提交于 2019-11-30 09:19:27
I want to allow anonymous/not yet registered and registered users to post on my website. Posts (table) - Id (int) - Subject (nvarchar) - Body (nvarchar) - UserId (uniqueidentifier) The project uses the latest MS technologies (ASP.NET MVC 5+, C#...) How should I go about doing that? Is ASP.NET Identity even the right solution? What's the difference between these: ASP.NET Identity SimpleMembership Membership Provider Update I need to be able to differentiate not yet registered users and record their postings in the database. Update 2 Then have the option to migrate to a registered account. Just