asp.net-mvc-5.1

An asynchronous operation cannot be started at this time

蹲街弑〆低调 提交于 2019-12-12 16:16:32
问题 I am making a call to asynchronous operation with the following line of code: Task.Run(() => { _emailService.SendEmail(email); }).Wait(); public async Task<bool> SendEmail(EmailTemplate email) { try { using (Client) { await Client.SendMailAsync(email.Message); return true; } } catch (Exception ex) { Logger.Fatal(ex.ToString(), "Error occurred while sending an Email."); return false; } } When the code ran the first time, it worked without issues and I received my email, however when I run it

Does Html.EditorFor support more than class in MVC5.1?

徘徊边缘 提交于 2019-12-11 10:31:19
问题 Without modifying my Editor Templates, is it possible to pass other HTML attributes into the Html.EditorFor Helper extension? The example shows a class being passed in: @Html.EditorFor(model => model.information, new { htmlAttributes = new { @class = "form-control" }}) There are many potential scenarios but I want to decorate my input with a data-myvar="value" . When I try this I get compiler errors invalid anonymous type declaratory . @Html.EditorFor(model => model.information, new {

$routing is automatically reload angularjs and hang the page

不想你离开。 提交于 2019-12-11 03:22:49
问题 app.js file is var app = angular.module('TaskApp', ['ngRoute']); app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider. when('/Home/Index', { controller: 'TaskManager', templateUrl: '/Home/Index' }).otherwise({ redirectTo: "/" }); $locationProvider.html5Mode(true); }]); app.controller('TaskManager', function () { //$location.path('/'); }); <!DOCTYPE html> <html ng-app="TaskApp"> <head> <meta charset="utf-8" /> <meta name="viewport"

Ajax post a form (validation) in MVC AsP.net?

只谈情不闲聊 提交于 2019-12-11 01:58:28
问题 So I have a page that have a few forms on it and one of those forms is a one for addresses which has three functions. Save as new, Update and Delete. I want to use form.submit() to fire the MVC validation on the client and server side but I dont want the entire page refresh. So this is what I want to use the simple form.submit() to gather the elements and send it to the ASP.net MVC controller as a model and handle the validation based on the attributes I have on the model and use a callback

dotless on Azure Web Project doesn't understand &:extend

北城余情 提交于 2019-12-10 15:11:07
问题 I'm using Azure SDK 2.2 and created a brand new MVC 5 web project. I added dotless, bootstrap-less (and subsequently updated to the latest LESS from getbootstrap.com), and font-awesome. I'm updated to the latest of everything and resolved the issue where dotless added a section to my web.config file and caused the project to return a 500 internal server error. That configuration has moved to according to the error. Now the page loads, but there is an issue with the bootstrap compilation from

Testing framework says entity has no key defined for built in entity

风格不统一 提交于 2019-12-09 15:59:08
问题 Castle.Proxies.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. I am trying to setup tests for my MVC 5.1 project which uses EntityFramework version 6.1, AspNet.Identity.Core version 2.0, AspNet.Identity.EntityFramework version 2.0. My only test case is very simple and it is erroring with the above error for 'IdentityUserLogin' and for Entity Type 'IdentityUserRole' as soon as I try to run. The problem is that as far as I understand

Why doesn't SuppressFormsAuthenticationRedirect work in AuthorizeAttribute.HandleUnauthorizedRequest override?

限于喜欢 提交于 2019-12-08 17:40:29
问题 I've got an MVC 5.1 site with a controller with a single POST action. I have an Android app that I want to POST to it using basic authentication. I created a BasicAuthorizeAttribute class and applied it to my controller, and for testing purposes make it reject everything: public class BasicAuthorizeAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { return false; } protected override void HandleUnauthorizedRequest(AuthorizationContext

Predefined type System.Object is not defined or imported

倾然丶 夕夏残阳落幕 提交于 2019-12-06 20:00:09
问题 I'm having this weird error only in .cshtml files in VS 2015. The error doesn't show up when I open the project with VS 2013. Error CS0246 The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) here are my references: <ItemGroup> <Reference Include="Microsoft.CSharp" /> <Reference Include="Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>N:\XXX

MVC5 and Bootstrap3: Html.EditorFor wrong class? How to change?

本小妞迷上赌 提交于 2019-12-06 17:10:50
问题 I just noticed that MVC 5 is using a different class for input fields when using EditorFor. I think its from a lower version of bootstrap, so the current class doesn't really add up. I'm talking about this: <div class="form-group"> @Html.LabelFor(model => model.Contact.CellphoneNo, new { @class = "control-label col-md-4"}) <div class="col-md-8"> @Html.EditorFor(model => model.Contact.CellphoneNo) @Html.ValidationMessageFor(model => model.Contact.CellphoneNo) </div> </div> Which results to

Cascading DropdownList with MVC5, Ajax, C# and MSSQL Server

為{幸葍}努か 提交于 2019-12-06 08:36:11
I'm quite new to MVC coming from windows forms and 3 tier architecture. I'm trying to figure out using cascading dropdownlists (DDL) populated from database. Im using MS SQL Server 2012, VS 2013 Currently I'm work on user questionnaire which users can select from multiple answers from DDL. Depend on some selections I need to change answers (again DDL) on next question. Database: Table DDLStacks : StackId | StackName 1 | Berry 2 | BerryColor 3 .... Table DDLStackContents (SCId Stack content id, indexing purpose) SCId | StackId | GroupId | Key | Value -------------------------------------- 1 | 1