asp.net-mvc-5

System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter Error

烂漫一生 提交于 2019-12-06 05:12:00
问题 I am trying to upgrade my asp.net project from Mvc 4 to 5. I followed these instructions: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 When I want to compile my project I am getting following error : Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly 'System.Net.Http.Formatting, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' If I add the reference to

.Net MVC 5.2.3: how to create a disabled option out of SelectListItem?

自闭症网瘾萝莉.ら 提交于 2019-12-06 04:54:56
I am trying to create a dropdown list with a few options disabled so that they are not selectable. Here is my code: var places = new SelectList(new List<SelectListItem> { new SelectListItem { Selected = false, Text = "Virgin Islands", Value = "Virgin Islands"}, new SelectListItem { Selected = false, Text = "", Value = "", Disabled= true}, new SelectListItem { Selected = false, Text = "Canada", Value = "Canada", Disabled= true}, new SelectListItem { Selected = false, Text = "", Value = "", Disabled= true}, new SelectListItem { Selected = false, Text = "Other", Value = "Other"}, }, "Value",

Custom Error pages in MVC 5

 ̄綄美尐妖づ 提交于 2019-12-06 04:53:07
I have been trying to configure Custom Error pages in ASP.NET MVC 5 but with little complete success. To do this, I have followed this guide: http://benfoster.io/blog/aspnet-mvc-custom-error-pages Web.config customerrors <customErrors mode="On" defaultRedirect="~/500.aspx" redirectMode="ResponseRewrite"> <error statusCode="401" redirect="~/401.aspx" /> <error statusCode="403" redirect="~/401.aspx" /> <error statusCode="404" redirect="~/404.aspx" /> </customErrors> Web.config httpErrors <httpErrors errorMode="Custom" > <remove statusCode="401" /> <error statusCode="401" path="401.html"

Why does Ajax work correctly on first request, but returns partial view on new page on second request?

淺唱寂寞╮ 提交于 2019-12-06 04:51:45
问题 I have an Ajax form nested within each row in a table to provide an add / remove feature. The partial lists all roles available (Microsoft identity 2.0), and for each, whether the specified user is associated with that role or not, as well as a button to toggle the user in and out of the role (Ajax). Everything works fine when I use Ajax.Beginform, however when I use regular jquery, it works the first time I click the button to toggle the user's association with a role, but the second time it

Min and Max values for EditorFor

妖精的绣舞 提交于 2019-12-06 04:47:17
问题 I've been trying this code to set minimum and maximum on my EditorFor : <label id="LbStartYear" style="width: 200px">From Date: @Html.EditorFor(model => model.SelectedYearBegin, new { htmlAttributes = new { @min = "0", @max = "20" } })</label> But no success. Minimum and Maximum are never set. I tried removing the quotation from 0 and 20 , also tried with and without the @ . Any ideas? 回答1: Simply use Range DataAnnotation attribute on your model property. By using this attribute you can

There was an error running the selected generator . try rebuilding the project

前提是你 提交于 2019-12-06 04:38:03
问题 When I create the Scaffold and add the Model class then I am getting these error "There was an error running the selected generator . try rebuilding the project" I have three Model class : 1.Department.CS 2.Designation.cs 3.CompanyDBContext.cs Database : I have two table in database, 1. Department(deptID,deptName,Description) 2. Designation(desgtID,desgName,description) Objective :- I want to create one view page for these scenario. Like this Insert Name of Form (TextBox) + Department Name

“The ConnectionString property has not been initialized.” - but only when publishing

梦想的初衷 提交于 2019-12-06 04:17:11
I have an MVC5 / EF6.1 website that runs perfectly on my development machine using LocalDb. However, when I publish this to an Azure Website with an Azure SQL Database, I get the following error when doing any database interaction: The ConnectionString property has not been initialized. I've searched all over and can't find the reason that this happens on Azure. The first file the stack trace points to is IdentityModels.cs:45 That contains the following: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } } When

“Value cannot be null or empty. Parameter name: contentPath” on a most unexpected line on postback when ModelState has errors

▼魔方 西西 提交于 2019-12-06 04:13:27
问题 It's been two hours straight I have been haggling with this monstrosity. I get this error: Value cannot be null or empty. Parameter name: contentPath On this line in my view: @Html.ValidationMessageFor(model => model.IssueName, "", new { @class = "text-danger" }) The stack trace given below seems to suggest that a call to Url.Content has been made, but I have made no such call. Below is the stack trace and that is followed by some more lines of code around the line which causes the error:

Configurable Application Insights Instrumentation Key

眉间皱痕 提交于 2019-12-06 04:08:47
问题 How can I best make the Application Inisghts' Instrumentation Key configurable in a way that allows an Azure Administrator to manage the settings for an App Services deployment of an MVC5 web application? Is there a certain event in an MVC application initialization where this should be done or is it okay to do it at pretty much any point? I am using the Trace Listener integration as well. By default, the Instrumentation Key (iKey) is set in the ApplicationInsights.config file. Additionally,

Dispose method in web api 2 web service

早过忘川 提交于 2019-12-06 04:02:56
问题 I am coding an MVC 5 internet application with a web api 2 web service. Do I need a dispose method for the DbContext class in a web service? It is not there as default. 回答1: Actually, System.Web.Http.ApiController already implements IDisposable : // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. // ... public abstract class ApiController : IHttpController, IDisposable { // ... #region IDisposable public void