asp.net-mvc-5

Client-side validation not working in ASP.NET MVC5 with Bootstrap

无人久伴 提交于 2019-11-30 07:58:27
Running Visual Studio 2013, I created a new ASP.NET MVC (5) project, with Bootstrap. However, I'm unable to get unobtrusive client-side validation working. The model has [Required] attributes on the relevant properties and the view has ValidationMessageFor... tags for each field in the form. However, submitting the form causes the form to postback to server before validation messages appear. Using NuGet, I've installed jquery.validate and jquery.validate.unobtrusive and added them to the jquery bundle in App_Start . Yet it continues to stubbornly post back to server. F12 dev tools shows no JS

How to execute raw SQL query using Entity Framework without having to use a model?

你离开我真会死。 提交于 2019-11-30 07:51:42
I am trying to learn C# ASP.NET MVC 5. And I am trying to use Entity Framework for everything I do. However, I need to run a raw SQL query and return the results into an array. Here is what I have done so far. I created my context class which allows me to connect to a server and it also allows me to change the database at run time. Here is my context class using ScripterEngine.Models; using System; using System.Collections.Generic; using System.Data.Common; using System.Data.Entity; using System.Data.Entity.Core.EntityClient; using System.Data.SqlClient; using System.Linq; using System.Web;

Decoupling Microsoft.AspNet.Identity.*

元气小坏坏 提交于 2019-11-30 07:03:49
I am working in Visual Studio 2013 RC and am testing Forms Authentication using new Microsoft.AspNet.Identity.* packages. I would to integrate these concepts (Users, Roles, etc, etc) but want to use my own domain models (POCOs) which are in different assembly. I also don't want to create a dependency on Microsoft.AspNet.Identity.* dlls. Is that even possible? I found this article which says it is not, but the article is written based on Preview not RC versions of identity packages. I have updated my sample project which you can find here: Identity RC1 sample It now implements an entity

how to fix 'The field must be a date' on a datetime property in mvc

给你一囗甜甜゛ 提交于 2019-11-30 06:48:09
I need to capture date and time both for my model property. In my model class I have the following [Required] [DataType(DataType.DateTime)] public DateTime? CallBackDate { get; set; } When I enter a valid date time (e.g. 28/05/2015 15:55 ) I keep getting this error The field CallBackDate must be a date. I have seen similar question and tried various answers but nothing seems to get rid of this. I m using unobtrusive client side validation and I can't disable it. The source of the input field has the following markup <input autocomplete="off" class="jquery_datetimepicker form-control

Intermittent redirection loops during ADFS authentication

大兔子大兔子 提交于 2019-11-30 06:46:51
问题 I am using Owin to configure my ASP.NET MVC 5 (.NET 4.5, IIS 7/8) application to authenticate against a third-party ADFS setup: app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType }); app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions { Wtrealm = Settings.Auth.Wtrealm, MetadataAddress =

How to migrate from SimpleMembership to ASP.NET.Identity

与世无争的帅哥 提交于 2019-11-30 06:39:34
问题 Migrating from MVC4 to MVC5 and want to use ASP.NET Identity too but I am struggling to find anything that covers everything I think I need to do to migrate the Identity. Migrating an Existing Website from SimpleMembership to ASP.NET Identity suggests all I need to do is create an ApplicationUser and migrate the data, and other web searches give me sql scripts and passowrd hashing advice. But there are other loose ends that I'd like to clear up before I jump in. First - I have code to

Intermittent ASP.NET oAuth issue with Google, AuthenticationManager.GetExternalIdentityAsync is returning null

醉酒当歌 提交于 2019-11-30 06:35:36
I am trying to fix an intermittent issue when using Google as an external login provider. When attempting to login, the user is redirected back to the login page rather than being authenticated. The problem occurs on this line (line 55 of link below), GetExternalIdentityAsync returns null. var externalIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie); The full code is: [Authorize] public abstract class GoogleAccountController<TUser> : Controller where TUser : Microsoft.AspNet.Identity.IUser { public IAuthenticationManager

Checking image mime, size etc in MVC

a 夏天 提交于 2019-11-30 06:07:29
问题 I have found here a pretty good way of checking whether the file uploaded by the user is a picture or not, how ever I ran into problems when I tried implementing it. Here is the class I have found to check files public static class HttpPostedFileBaseExtensions { public const int ImageMinimumBytes = 512; public static bool IsImage(this HttpPostedFileBase postedFile) { //------------------------------------------- // Check the image mime types //------------------------------------------- if

viewmodel returns null on postback mvc 5

假如想象 提交于 2019-11-30 05:58:12
问题 I have this problem with a viewmodel, when the view is posted I'm getting null values for all the properties. I've researched a bit, I can see multiple ppl have this problem, I tried some of the solutions but none of them works for me. This is what I have: Viewmodel: public class EventViewModel { public projectEvent ProjectEvent { get; set; } public List<eventType> eventTypes { get; set; } } Controller: [HttpGet] public ActionResult AddEditEvent(int? id) { var eventViewModel = new

What exactly does <system.codedom>/<compilers> do in web.config in MVC 5?

走远了吗. 提交于 2019-11-30 05:52:42
I am about to migrate a bunch of projects from .NET 4.0 + MVC 3 to .NET 4.5.2 + MVC5. To make this easier, I've created a new blank MVC project to compare DLL references and some other stuff such as web.config. In the latter, the following entries are generated by Visual Studio: <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="