asp.net-mvc-4

Implementing role based authorization in MVC and Web API with custom table

纵饮孤独 提交于 2021-02-20 04:21:05
问题 I have inherited an application with database. The database has following tables related to authentication and authorization. User Table UserName Password UserTypeId UserType Table UserTypeId UserTypeDesc The User Type table stores the roles for the user e.g. Admin, Editor, etc. If I want to implement authorization like below [Authorize(Roles="Admin, Editor")] public IHttpActionResult GetOrders() { //Code here } Where and what should I code so that the roles are available to the authorize

Model is Null while passing by Ajax Call MVC?

柔情痞子 提交于 2021-02-19 05:27:52
问题 I am new bird in MVC. I want to pass the Model into the Ajax call, i write the following code to do so. But it always passing NULL to all properties. $("#btnsubmit").click(function () { alert('hello'); var productModel = { Name: 'ram@mailinator.com', Address: "Chai" }; $.ajax({ type: "POST", url: '@Url.Action("ContactDistributor", "AjaxCallTest")', contentType: "application/json; charset=utf-8", data: JSON.stringify({ model: productModel }), dataType: "json", success: function () { alert(

Passing JSON Object and List of Objects to ASP.Net Controller [duplicate]

做~自己de王妃 提交于 2021-02-19 03:38:12
问题 This question already has answers here : Post JSON array to mvc controller (3 answers) Closed 5 years ago . I need some help with the hereunder please. I have these 2 models and the method I will be using them in hereunder. public class RoleModel { public string Name { get; set; } public string Description { get; set; } public List<PermissionGroupModel> PermissionGroups { get; set; } } public class PermissionGroupModel { public int PermissionGroupID { get; set; } public string Name { get; set

MVC Redirect after login

雨燕双飞 提交于 2021-02-19 01:08:46
问题 I have an AccountController where users can login, and an area named Admin where users have to been autorized to see. When users log in with correct username and pw, it redirects to the same page again ( ../Account/Login?ReturnUrl=%2FAdmin ) AccountController public class AccountController : Controller { [AllowAnonymous] public ActionResult Login() { return View(); } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(LoginModel model, string returnUrl) { if

Passing C# variable using MVC/Razor for use with Dygraph

安稳与你 提交于 2021-02-18 19:47:55
问题 So here is my problem, and I'm sure it's something very simple. I'm relatively new to Web Development and I'm running into a little problem that I just can't figure out. I have this code in an MVC view. . . @{ var data = ""; var count = 1; foreach (var item in ViewModel.Data) { data += count.ToString() + "," + item.Reading.ToString() + "\n"; count++; } } I want to pass this 'data' variable to a very tiny script in order to create a graph using Dygraph. This is what I currently have, and

Passing C# variable using MVC/Razor for use with Dygraph

橙三吉。 提交于 2021-02-18 19:47:24
问题 So here is my problem, and I'm sure it's something very simple. I'm relatively new to Web Development and I'm running into a little problem that I just can't figure out. I have this code in an MVC view. . . @{ var data = ""; var count = 1; foreach (var item in ViewModel.Data) { data += count.ToString() + "," + item.Reading.ToString() + "\n"; count++; } } I want to pass this 'data' variable to a very tiny script in order to create a graph using Dygraph. This is what I currently have, and

MVC CSS on view page (not _layout) not working

北城余情 提交于 2021-02-18 18:54:56
问题 I have a problem with MVC4 CSS. i m including a CSS file named registration.css in an another view page named "registerUser.cshtml". This page is like a content page in mvc4 razor. but problem is that CSS is not working. How can i resolve this. I have also included in BundleConfig.cs as bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/registration.css")); But it is also not working. Help me. 回答1: Use @Styles.Render("~/Content/css") instead of @Styles.Render("~/Content

C# MVC4 Web API - Resulting JSON should return objects instead of $ref to object

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-18 11:11:50
问题 I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In the JSON I return, there are some cases where the same child node is present for multiple parent nodes. In these cases, the first occurrence of the child node is fully visible with all it's members. Any subsequent occurrence shows up as a $ref to the first occurrence. I'd like instead to see the full object everytime it shows up in the JSON returned. For example, instead of seeing: [{ "$id": "1", "userId": 1, "Badge": { "

C# MVC4 Web API - Resulting JSON should return objects instead of $ref to object

[亡魂溺海] 提交于 2021-02-18 11:10:05
问题 I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In the JSON I return, there are some cases where the same child node is present for multiple parent nodes. In these cases, the first occurrence of the child node is fully visible with all it's members. Any subsequent occurrence shows up as a $ref to the first occurrence. I'd like instead to see the full object everytime it shows up in the JSON returned. For example, instead of seeing: [{ "$id": "1", "userId": 1, "Badge": { "

How to create MVC 4 @Html.TextBox type=“file”?

一世执手 提交于 2021-02-18 10:29:45
问题 I need to add the following field at my form <input type="file" class="input-file" /> I create model and describe this field (the last field) using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CorePartners_Site2.Models { public class FeedbackForm { public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public string Company { get; set; } public string AdditionalInformation { get; set; } public