asp.net-mvc-5

ASP.NET MVC 5 Attribute Routing: Url.Action returns null

為{幸葍}努か 提交于 2019-12-10 16:25:05
问题 I am experiencing an issue with a refactoring of our payment processing action method (called by our 3rd-party online payment provider). We have a product controller with the [Authorize] and [RoutePrefix("products")] attributes at the class level, and action methods including the following: Product(string contractNumber) with routing attribute [Route("{productCode}")] MakePayment(string productCode, PaymentAmountType? amountSelection, decimal? amountValue) with routing attribute [Route("

MVC RadiobuttonFor Razor how to make label click able?

穿精又带淫゛_ 提交于 2019-12-10 15:15:10
问题 I'm trying to make a radiobuttonlist in razor syntax so far I have come up with this @foreach (var p in Model) { <div id="projectList" class="col-lg-5"> @Html.RadioButton("name", "1", false, new { onCLick = "ShowOption(this)", id = p.id.ToString() }) @Html.Label(p.id.ToString(), p.name) </div> } but the label isn't associated with the radiobutton. 回答1: Your foreach loop is not generating for attribute for the label (and if you removed new { id = p.id.ToString() } from the RadioButton method,

How do I configure the Users context/table?

大憨熊 提交于 2019-12-10 14:46:02
问题 With the new ASP.NET MVC 5 Preview released, how do I configure the Users context/table? In MVC 4 I would just use my own User class and then point the WebSecurity initialize to it, tike this: WebSecurity.InitializeDatabaseConnection(connectionString, "System.Data.SqlClient", userTableName, userIdColumn, userNameColumn, autoCreateTables); I wish to add additional properties to the Users class - how? 回答1: The UserStore and User classes are there to make EF based implementations easier, but you

How to remove comments with BundleTransformer YuiJsMinifier

一笑奈何 提交于 2019-12-10 14:44:32
问题 I am using BundleTransformer to minify css and js resources <yui> <css compressionType="Standard" removeComments="true" lineBreakPosition="-1" /> <js compressionType="Standard" obfuscateJavascript="true" preserveAllSemicolons="false" disableOptimizations="false" ignoreEval="false" severity="0" lineBreakPosition="-1" encoding="UTF8" threadCulture="en-us" /> </yui> As you can see for css it is possible to specify removeComments="true" But in js there is no such option. I red that YUI js

Can I access the parent view's Model from a child partial view?

こ雲淡風輕ζ 提交于 2019-12-10 14:29:46
问题 Can I access the parent view's Model from a child partial view? I get conflicting information when I look this up. If so, can anyone point me at an example? And if so, would it help to make the child model object a property of the parent model? 回答1: No.If you are talking about strongly binding the views with ViewModels then you can only access the model which you pass to your partial view.But if you want something to be available in partial view or any other view you can use ViewData

ASP.NET MVC 5 And Web API 2 .NET requirement

限于喜欢 提交于 2019-12-10 13:53:53
问题 My host provider only supports .NET 4. Is it possible to run MVC 5 and Web API 2 in .NET 4 machine? 回答1: Short Answer: No, you need .NET 4.5 Only if you add the dependencies: Razor v3.0+ ASP.NET WebPages v3.0+ 回答2: No, ASP.NET Web API 2 requires .NET 4.5: http://forums.asp.net/t/1937143.aspx?Is+ASP+NET+MVC+5+and+Web+API+2+0+supported+on+NET+4+0+and+IIS6+ (scroll at the very bottom) 来源: https://stackoverflow.com/questions/20411029/asp-net-mvc-5-and-web-api-2-net-requirement

HTML.EditorFor adding class not working

陌路散爱 提交于 2019-12-10 13:45:46
问题 I have problem with adding css class to HTML.EditorFor(). I was searching on the net if someone had the same problem but I couldn't find anything. Can you please help me? So, its not problem about css that class is not defined, it is, but simply, its not added to input field. This is the code in view: @model eVinogradarstvo.Models.DetaljiViewModel @{ ViewBag.Title = "Edit"; } @using (Html.BeginForm("PromijeniPodatke", "KorisnikDetalji", FormMethod.Post, new { enctype = "multipart/form-data",

How to check if session value is null or session key does not exist in asp.net mvc - 5

北慕城南 提交于 2019-12-10 13:39:53
问题 I have one ASP.Net MVC - 5 application and I want to check if the session value is null before accessing it. But I am not able to do so. //Set System.Web.HttpContext.Current.Session["TenantSessionId"] = user.SessionID; // Access int TenantSessionId = (int)System.Web.HttpContext.Current.Session["TenantSessionId"]; I tried many solutions from SO Attempt if (!string.IsNullOrEmpty(Session["TenantSessionId"] as string)) { //The code } Kindly guide me. Error: NULL Reference 回答1: if(Session[

ASP.NET Core WebAPI 500 Internal error in IIS 7.5

ぃ、小莉子 提交于 2019-12-10 13:35:08
问题 I'm struggling to get this WebAPI to work. Well, work with IIS. Everything works fine in IIS express, but when I publish it, specifically 1 api request doesn't work. I'm trying to access a url of API/[Controller]/{date}/{integer} . I keep getting the 500 server error. My other route of API/[Controller]/{date} works. Here's my API Controller: [Route("api/[controller]")] public class PostingsController : Controller { // GET: api/Postings/5 [HttpGet("{date}")] public string Get(string date) {

The name 'DefaultAuthenticationTypes' does not exist in the current context

て烟熏妆下的殇ゞ 提交于 2019-12-10 13:32:38
问题 I'm trying to implement role-based authorization in my web application like following: [HttpPost] [ActionName("Login")] public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { string userName = model.Username; string[] userRoles = (string[])Session["UserRoles"]; ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName)); userRoles.ToList().ForEach((role) => identity.AddClaim