asp.net-mvc-5

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

梦想的初衷 提交于 2019-12-10 09:40:47
问题 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 = "",

How to create array of key/value pair in c#?

心已入冬 提交于 2019-12-10 09:24:18
问题 I have an application that is written on top of ASP.NET MVC. In one of my controllers, I need to create an object in C# so when it is converted to JSON using JsonConvert.SerializeObject() the results looks like this [ {'one': 'Un'}, {'two': 'Deux'}, {'three': 'Trois'} ] I tried to use Dictionary<string, string> like this var opts = new Dictionary<string, string>(); opts.Add("one", "Un"); opts.Add("two", "Deux"); opts.Add("three", "Trois"); var json = JsonConvert.SerializeObject(opts); However

Open PDF in a new tab in browser

↘锁芯ラ 提交于 2019-12-10 05:17:45
问题 Never done this before so not sure what is involved in it. I did search and found many answers but they were more complex than what I need. For example they needed to zoom in, generate, create accurate thumbnail, embed the actual PDF in the webpage, etc... But my question is much simpler: If my guy that I am showing his information on webpage has some PDF to show I just want to put a generic PDF icon on the page, people click on it and the actual PDF opens in a new tab in their browser. What

Ajax json to MVC5 controller: Passing object containing a collection

被刻印的时光 ゝ 提交于 2019-12-10 05:00:36
问题 Folks, I've attempted this on MVC4 and MVC5. I need to pass an object with a few properties and a collection from the client to the controller. I've defined the model in C# as: public enum RequestMode { ReadOnly = 0, Edit = 1} public class DataRequest { public int ProjectId { get; set; } public RequestMode Mode { get; set; } public List<PageRequest> PageRequests { get; set; } public DataRequest() { PageRequests = new List<PageRequest>(); } } public class PageRequest { public int Id { get; set

WWWROOT in MVC5

╄→гoц情女王★ 提交于 2019-12-10 04:35:55
问题 How to achieve same behavior in ASP.NET MVC5 with static files like it works on aspnet-core with app.UseDefaultFiles(); app.UseStaticFiles(); ? I mean serving static files from some folder over root, e.g. /wwwroot/some.html must be opened on mysite.com/some.html , /wwwroot/img/test.jpg on mysite.com/img/test.jpg etc. Update : I have created wwwroot folder and added following rule to web.config : <system.webServer> <rewrite> <rules> <rule name="Rewrite Static" stopProcessing="true"> <match url

How do I check EntityValidationErrors when validation fails?

試著忘記壹切 提交于 2019-12-10 04:13:29
问题 I get this message when I try to edit a property in MVC 4 database first project. I'm using the MVC default edit page. "Validation failed for one or more entities. See "EntityValidationErrors" property for more details." Where do I check for validation? 回答1: Go to your edit function, put a try - catch block and catch the exception - ' DbEntityValidationException ' if you want to see the errors, iterate though the validation errors. here is a simple code example. catch

Does System.Diagnostics.Trace have any performance degredation?

眉间皱痕 提交于 2019-12-10 04:00:00
问题 I am looking for a simple native .NET error logging solution. I am not interested in using log4net, Elmah or any other logging library. Below is what I am planning on using. My question is performance on my site is paramount and does this flow introduce any performance concerns? Global.asax protected void Application_Start(object sender, EventArgs e) { GlobalFilters.Filters.Add(new HandleExceptionsAttribute()); } Handle Exceptions Attribute: public sealed class HandleExceptionsAttribute :

Lodash - '_' refers to a UMD global and lodash.js is not a module errors

怎甘沉沦 提交于 2019-12-10 03:34:41
问题 If I do nothing and add the type definition it works for jquery but lodash gets a '_' referes to a UMD global, but the current file is a module. Consider adding an import instead. If I try to import lodash with any combination of import call, I get lodash.js is not a module I tried to get help by asking a question here and it was closed because there was another answer for Angular (Angular 2). I really need a real answer so I'm re-posting with my own solutions, hoping someone will eventually

MVC DropDownList selected value not working

牧云@^-^@ 提交于 2019-12-10 03:24:13
问题 I am using MVC 5. I have my ViewBag for list as ViewBag.TitleList = new SelectList((new string[] { "Mr", "Miss", "Ms", "Mrs" }), contact.Title); //contact.Title has selected value. then I tried converting the array to SelectListItem ( to no avail) On the View it looks like @Html.DropDownListFor(model => model.Title, ViewBag.TitleList as SelectList, "Select") also I tried @Html.DropDownList("Title", ViewBag.TitleList as SelectList, "Select") The list loads successfully but the Selected Value

ASP.NET MVC tries to load older version of Owin assembly

五迷三道 提交于 2019-12-10 03:17:16
问题 As a bit of context, I'm developing an ASP.NET MVC 5 application that uses OAuth-based authentication via Microsoft's OWIN implementation, for Facebook and Google only at this stage. Currently (as of v3.0.0, git-commit 4932c2f), the FacebookAuthenticationOptions and GoogleOAuth2AuthenticationOptions don't provide any property to force Facebook nor Google respectively to reauthenticate users (via appending the appropriate query string parameters) when signing in. Initially, I set out to