FAQ Database Discussion Community


Visual Studio MVC 5 and SQL Server Express inquiry

sql-server,asp.net-mvc,visual-studio-2013,asp.net-mvc-5
I am attempting a simple MVC 5 web application. I had it on LocalDB and it was find. Now I want to use SQL Server Express. Just would like to ask: Does the sequence has to be: 1, Designing your models, 2, Connecting to SQL Server from my Visual Studio...

Web API Basic Auth inside an MVC app with Identity Auth

c#,authentication,asp.net-web-api,asp.net-mvc-5
So I have a C# MVC app using Identity for its authentication. I now have a need to expose a few things via Web API to some of my clients. Instead of building a separate app, project, deployment... I've simply added an API Controller to my existing project. To keep...

Web API AuthorizeAttribute does not return custom response

c#,asp.net-web-api,asp.net-mvc-5
How can I make IsAuthorized return my custom object while function returns false? In my WebAPI project I have a class like; public class CustomAuthorizeAttribute : AuthorizeAttribute { protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext) { StandardWebAPIResponse invalidUserResponse = new StandardWebAPIResponse() { code = (int) Constants.ErrorCodes.InvalidCredentials, data = "InvalidCredentials.", StatusCode = HttpStatusCode.Unauthorized...

ViewModel “no key defined” error

c#,asp.net-mvc-5,entity-framework-6
I've recently been learning asp.net MVC 5 and EF6 and i've started to develop viewmodels for my views instead of stuffing values into the viewbag. I this is my viewmodel called EmployeeCreate namespace Rota.ViewModels { public class EmployeeCreate { public string FirstName { get; set; } public string LastName {...

Display a view in _Layout.cshtml?

.net,asp.net-mvc-5
I have followed this tutorial to generate a dynamic list menu http://dotnetawesome.blogspot.se/2014/06/how-to-create-treeview-with-database-data-mvc4-aspnet.html This is the view @model List<Project.Models.Treeview> @{ ViewBag.Title = "Simple"; } <h2>Simple Treeview from Database Data</h2> <div style="border:solid 1px black; padding:10px; background-color:#FAFAFA"> <div class="treeview"> @if (Model != null && Model.Count() > 0) { <ul> @Treeview.GetTreeView(Model,...

Why is '+' Character Removed From Url

c#,asp.net-mvc-5
Why does Mvc remove + from code=wamTEpI6kZcP997j2d+ZeQ== link http://localhost:33693/PasswordRecovery/[email protected]&code=wamTEpI6kZcP997j2d+ZeQ== Controller Func public ActionResult InitPassword(string email, string code) { return View(); } ...

ApplicationUser ICollection member not being saved in DB

c#,.net,entity-framework,asp.net-mvc-4,asp.net-mvc-5
I've added some properties to ApplicationUser, and two of them are ICollection's. When I use Update-Database it doesn't generate columns for these two members. So, what am I missing here? I imagine it's very basic. I'm used to working with Hibernate in Java, where it generates a new table for...

MVC5 Scaffolding Dropdowns Out the Box

asp.net-mvc,asp.net-mvc-5,poco,html.dropdownlistfor,asp.net-mvc-scaffolding
I want to view, edit and create with drop-down list of my lookup relationships. Sometimes this works, sometimes it doesn't. It's a mystery that I'm hoping can be definitely solved here. Here's my POCO's for the lookup public class Color { public int Id { get; set; } public string...

MvcSiteMapProvider MVC5 External URL Re-routing to Home Controller / Index Method

asp.net-mvc-5,mvcsitemapprovider
I'm using MvcSiteMapProvider 4.6.18. Many of my menu items link to external sites; however, the "url" attribute of mvcSiteMapNode is not being carried over to the menu. That is, I can see the url in the source, but the link is referring to the parent mvcSiteMapNode controller and action and...

Convert string value to english word

c#,asp.net-mvc-5
I'm trying to figure out / where to start in regards to this situation say for example I enter $127.45 in to a textbox I would expect the application to spit back one hundred and twenty-seven dollars and forty-five cents The word will then be placed on a document and...

Resource Not Found - 404

asp.net,asp.net-mvc-5
So, I've copied a few methods from one controller to another, moved the respective views into the correct view folder and tried to debug my project.. After trying to navigate to one of the newly copied methods and views I get hit with this lovely error. Server Error in '/'...

Click actionlink on view, controller checks condition, returns JSON, jQuery Ajax doesn't work

ajax,json,controller,asp.net-mvc-5,actionlink
Click ActionLink on view, controller checks condition, returns JSON, JQuery Ajax doesn't work. Click the "Delete" ActionLink, "Delete" controller if customer's "Orders" property is null, if not null, a message will be popped up. If null, process to "Delete" view. Here are the codes: 1, on the view, the @Html...

MVC5 Login to custom Database

asp.net-mvc,authentication,login,asp.net-mvc-5,owin
What if you have your own database and a BAL (Business Access Layer) and don't want to use DefaultConnection and the template ASPNET database tables but my own user tables? How can you use a custom database? ConnectionString: public class AppDbContext : IdentityDbContext<AppUser> { public AppDbContext() : base("DefaultConnection") { }...

How to automatically update the database on application start up

c#,asp.net-mvc,asp.net-mvc-5
A run time error occurs when i run my code asking me to do a code migration to update my database. I am not sure how to do this, can anyone help me? The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First...

When pushing a button inside a partial view, parent form is validated

asp.net-mvc,validation,asp.net-mvc-5
In a MVC 5 application, I have a partial view with a button to submit some information. But when I push that button the parent form is validated, making all the validating errors displayed. All I want is that only the validated fields in the partial view are executed with...

Inherited Property of Model is always returning Null Value

c#,asp.net,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-5
I have a view which displays a radiobutton list on left side of the page and it also loads a partialview on right side of the page which consist of various filters to be selected before displaying a report in a popup window. The problem is that the property named...

MVC/Razor: Error at Viewbag.Title

c#,asp.net-mvc,razor,asp.net-mvc-5
I have two methods: public ActionResult Index() { var propList = db.Properties .Where(x => x.SiteVisibilityFlags.HasFlag(Enums.SiteVisibilityFlags.Corporate) || (x.SiteVisibilityFlagsOverride == true && x.SiteVisibilityFlagsOverrideValue.HasFlag(Enums.SiteVisibilityFlags.Corporate))) // just ones visible to 'Corporate' .ToList(); // Use view model var pDVMs = DomainModelsToViewModels(propList); return View(pDVMs); } public ActionResult Region(string id) // (regionId/marketId) { // make sure to...

How to get routevalues from URL with htmlhelpers or JavaScript?

javascript,asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-routing
I have this MVC MapRoute routes.MapRoute( name: "Authenticated", url: "{controller}/{action}/{foo}/{bar}", defaults: new { controller = "Home", action = "WelcomePage", Foo = "0", Bar = "0" } ); And URL http://localhost/mysite/controller/action/2/1 How can I with JavaScript recieve the 2 and 1? I would prefer a solution with as little substring work...

Produce different serialized JSON for a given class in different scenarios

c#,json,serialization,asp.net-mvc-5,json.net
Update 1: for reasons I won't go into, I want to avoid having anything other than the properties to be persisted in my entity objects. This means no extra properties or methods... I have an entity called Entity1 with (say) 10 public properties. In one place in my code I...

Why my ajax call do not work?

ajax,asp.net-mvc,asp.net-mvc-5,asp.net-ajax
I am not able to detect why my ajax call do not work. I am trying to read the contents of text file but it do not work, The problem is control never go to .done(function(data)) function makeCustomerTree() { // debugger alert('customertree'); $.ajax( { url:"~/bootstrap/js/LiveMap/Ajax/JsonStringCarryingData/customer-tree-json.txt", data: {}, type: "GET" }).done(function...

MVC 5 - Validate a specific field on client-side

javascript,jquery,asp.net-mvc,validation,asp.net-mvc-5
I want to populate a city/state drop down list based on the postal code a user types into a textbox. So when the text changes, I'm going to make an ajax call to retrieve the data. However, I only want to perform that ajax request for valid postal codes. The...

C# mvc5 - Easy way to check if user is authenticated in each controller method

c#,asp.net-mvc-5
I have a controller that I only want authenticated users to be able to access. Do I have to put a check in each method in my controller to verify a user is authenticated, or is there another way to handle this? Can I use annotations to do this instead?...

Return to second to last URL in MVC (return View with previous filter conditions applied)?

c#,asp.net-mvc,razor,asp.net-mvc-5,grid.mvc
I'm working on an MVC5 application. On the home screen is a grid allowing users to view Data and be transferred to a number of Views for various actions on each record. One of these is an [EDIT]. The issue I'm encountering is as follows: due to the amount of...

EPPlus: how can I assign border around each cell after I apply LoadFromCollection?

c#,asp.net-mvc-5,epplus
In my export ActionResult I was able to load the model into my ExcelPackage. Where I am having trouble is assigning a border around each cell once LoadFromCollection is applied. While the AutoFitColumns correctly applies, the border style I applied only works on Cells["D1"], but not on the table. BorderAround...

An unhandled exception of System.InvalidOperationException breaks my MVC App?

c#,asp.net-mvc-5,antiforgerytoken
I am taking the concept of building a OWIN login from a empty MVC and I am just starting to add the part with using my database to login the user after creating a Identity claim to put in the URL. This is my code to create the claim to...

Knockout js unable to bind data using observableArray

knockout.js,asp.net-mvc-5
I am trying to display all the employees in the database and I am unable to achieve it. My JS, var EmployeeKoViewModel = function () { var self = this; self.EmpId = ko.observable(""); self.Name = ko.observable(""); self.City = ko.observable(""); self.Employees = ko.observableArray([]); GetEmployees(); function GetEmployees() { $.ajax({ type: "GET", url:...

When should I use ViewBag/model?

c#,model,asp.net-mvc-5,viewbag
I think that using ViewBag is faster than model. My example is: In the action: public ActionResult MyAction() { ViewBag.Data = (from m in myDatabase.myTable select m).ToList(); } In the view: @foreach(var item in ViewBag.Data) { <tr> <td>@item.myColumn</td> </tr> } By using model: [Table("tbl_mytable")] public class MyTable() { public int...

LINQ: Searching inside child entities

c#,linq,asp.net-mvc-5
I have 'Property' objects with 'BayOption' child objects. I need the site search to search through the child BayOptions as well as the Properties and return Properties if the search criteria matches the child or parent. A Property can have multiple BayOptions (and usually does). I was unsure if .Select...

How to upgrade mvc2 to mvc5?

asp.net-mvc,asp.net-mvc-2,asp.net-mvc-5
I've got an old project from a friend that he wants me to do redo. How ever that project is written in ASP.net mvc2. So When I try to open it in visual studio 2013 I can errors. Saying the file is incompatible. How would I go ahead and fix...

Get desired html element's attribute value and set to hidden field before binding in Asp.Net MVC

c#,.net,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-5
Let's say such hidden field has genereated: <input data-val="true" data-val-number="The field MemberRelationId must be a number." id="MemberRelationId" name="MemberRelationId" type="hidden" value="3"> As you seem it has a value 3. It means that, user has already set the value for this field. But, he(she) can also change this value and I must...

ASP.NET MVC 5 - “Create” view that can handle any number of elements for an IEnumberable based on clicking an “Add row” button?

c#,asp.net,asp.net-mvc,asp.net-mvc-5,partial-views
I am writing a recipe manager for my wife in C#/.NET MVC 5. I'm getting to the page for creating a recipe, and I'm a little stumped. A recipe consists of a Name and a list of ingredients. When I create a view, I have my form: @using(Html.BeginForm()){ //Form elements...

AD Group authorisation in MVC5 web app

asp.net-mvc,active-directory,asp.net-mvc-5
It was similar to the linked answer but I used the following syntax instead: Ended up using [Authorize(Roles = "DOMAIN\\Group")] in the controller which worked perfectly I have a web app, that I've completed now and the only things outstanding are to: Upload to a web server; Make it so...

Pass routing value to Html.BeginForm using javascript

javascript,c#,asp.net-mvc,asp.net-mvc-5
I currently have panels and each panel has an ID associated with it which is held in the data-id attribute of each panel. I can get this easily through JavaScript. One the panels I have a delete button which will delete the panel and it's entry within the database. Once...

How to create a declarative HTML helper in MVC 5

asp.net-mvc-5
my scenario: I am finally getting around to creating my own blog, and I am trying to learn as much as possible with regards to MVC while doing so. I am trying to display my tags as a custom declarative helper in my "PostView.cshtml" file but my problem is that...

Web API Controller not found on PUT

jquery,asp.net-mvc,asp.net-web-api,asp.net-mvc-5,put
I am having trouble finding the put action of a web api 2 controller. I'm using MVC5. The GET action in the controller is found and is working well when called. I have tried several different ways of hitting this, but to no avail. I would appreciate any hints. The...

How to get .net web api in jsonP, although it returns json data by default

asp.net-mvc,asp.net-mvc-4,asp.net-web-api,asp.net-mvc-5,asp.net-web-api2
I am working on .net web api in Asp.net Mvc5 project... By default it returns xml or json...in my project json/xml data returning fine... I am looking for the setting so that i can get response in JSONP.... Web Api config : public static void Register(HttpConfiguration config) { // Web...

How to append Urls in angular routing?

asp.net,angularjs,asp.net-mvc-5,angularjs-ng-repeat,angular-ui-router
How to do url(string) cocatenation in angular routing. Please refer the below snippet to understand my question. app.config(['$routeProvider', '$location'], function($routeProvider) { when('/', { templateUrl: '/AlbumsList.html', controller: 'a1Ctrl' }). when('/albums/:albumName', { templateUrl: 'AlbumsList.html', controller: 'b1Ctrl' }) }) app.controller('a1Ctrl', function($scope, $http) { $scope.albums = function() { //ajax getting data from server }...

Store does not implement IUserLockoutStore

asp.net-mvc-5,asp.net-identity
I'm trying to implement own DAL for asp.net Identity 2.0 with functionality that I need. I don't need Account Lockout functionality. But When I try to call var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false); I get System.NotSupportedException:Store does not implement IUserLockoutStore<TUser>. So why should I need to implement...

MVC: after export to excel, index action result is not getting called

asp.net-mvc-5,export-to-excel
I have one MVC application, in which export to excel functionality is given. I want to redirect Index action once export is finished. I have written below code but it not redirected to index action. what i missed here ? output = new MemoryStream(); workbook.Write(output); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}",...

How to pass a value for input type=“number” to JS in Razor View

razor,asp.net-mvc-5
I have a view, here's a fragment of it: @foreach (var item in Model.Items.ToList()) { <tr> <td> <input type="checkbox" name="productIdCheckbox" value="@item.sLabel"> </td> <td> @Html.DisplayFor(modelItem => item.sLabel) </td> <td> @Html.DisplayFor(modelItem => item.Text) </td> <td> @Html.DisplayFor(modelItem => item.OEMCode) </td> <td> <input type="number" name="qty" id="qty" min="1" max="1000" step="1" value="@item.Quantity" /> </td> <td> <input...

Understanding ASp.net Identity key points

asp.net-mvc-5,entity-framework-6,asp.net-identity-2
I am an Asp.net developer but very much new to the Asp.net Identity framework. I have been studying the sample application and followed some tutorials too on Identity but still I am not able to grasp the concept completely. I have very firm grip over Asp.net membership but Identity seems...

Best way to exclude some properties from binding

asp.net-mvc,asp.net-mvc-5,model-binding
One of my classes has some properties that I want model binder to always ignore them. Currently I'm using [Bind(Exclude ="")] in the action methods, like this: public ActionResult Edit([Bind(Exclude = "prop1, prop2, prop3")] BusinessModel model) This class has been used in several action methods. Do I have to manually...

How do I properly send __RequestVerificationToken with an ajax request in MVC5

ajax,asp.net-mvc,asp.net-mvc-5
I'm trying to send an ASP.NET AJAX request to my application. In the application's controller, I have: [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Edit([Bind(Include = "ID,Name,Instructions,Glass,Notes")] Drink drink, [Bind(Include= "ID,Amount,Brand,IngredientID,DrinkID")] IEnumerable<DrinkIngredient> DrinkIngredients) { if (ModelState.IsValid) { //and so on my javascript looks like this: console.log($('#editDrinkForm').serialize()) var x = new XMLHttpRequest(); x...

How to use ajax to post json string to controller method?

jquery,asp.net-mvc,visual-studio-2013,asp.net-mvc-5
I want to be able to post a json string to a control action but it's always receive the string as null. If I create a view model for the controller method, it works, but that's not what I want since there will be too much view models to maintain....

Only parameterless constructors and initializers are supported in LINQ to Entitier in dropdown

.net,asp.net-mvc-5
I have this controller public ActionResult Create() { var db = new MyDbContext(); IEnumerable<SelectListItem> items = db.FileUploadCategories .Select(c => new SelectListItem { Value = c.ParentCategoryID.ToString(), Text = "--" + c.CategoryName }); ViewBag.Categories = items; return View(); } And a view like this @Html.DropDownList("ParentCategoryID", (IEnumerable<SelectListItem>)ViewBag.Categories, "-- Select --", new { @class...

Getting and passing MVC Model data to AngularJS controller

javascript,asp.net-mvc,angularjs,razor,asp.net-mvc-5
Hey guys so I'm pretty new to AngularJS and I'm at a loss here. Right now my MVC program uses Razor to display all the data in my .mdf database (i.e: @Html.DisplayFor(modelItem => item.LastName) ). However, I want to go mostly Angular. I am trying to use ng-repeat to display...

Null attribute in MVC 5 not rendering. What kind of magic is this?

c#,asp.net-mvc-5
<form name="mailform" id="mailform" method="post" action="@(ViewBag.Test)" class="testForm"> What I thing that this will render my action attribute like action="" (in case of ViewBag.Test = null) but I am confused with ASP.NET MVC's behaviour. When ViewBag.Test is not defined than my action attribute is not rendering. For confirm I open the View-source...

Why can't the value of ViewBag be cleared after PostBack?

c#,asp.net-mvc-5
My controller name is "demo". I write 2 actions with the same name "Index". The first uses [HttpGet] and the seconds is [HttpPost]. But, when I require a PostBack from View, the value of ViewBag.Name in the action [HttpGet] public ActionResult Index() {} can't be cleared. [HttpGet] public ActionResult Index()...

Embedding a Silverlight App into a MVC

c#,asp.net-mvc-5,silverlight-5.0
I decided to convert the WPFs into a Silverlight applications. My only problem is trying to get it to display the silverlight application in my MVC web browser. I added all of my silverlight projects into my MVC project. I am just not getting it to show my silverlight application....

Checkboxes array of bools doesnt brings the true value if it's checked by user

asp.net-mvc,controller,asp.net-mvc-5,views
I have a list of Checkboxes in a bool array, I wish I could give the Checked value as a "true" in that specific checkbox if it's checked by user This is my model using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; namespace testnumbers.Models { public class StringNumber...

In MVC Razor, how can I correctly add querystring parameters to an html.actionlink?

asp.net-mvc,razor,asp.net-mvc-5
I have an MVC Razor page where I am trying to add a querystring parameter to the URL. <td> @Html.ActionLink(item.Student_Name, "Index", "FourCourseAuditDetails", new { filterByStudent = item.Student_Name}) </td> My desired outcome is: http://[server]/FourCourseAuditDetails/Index?filterByStudent="[item.Student_Name]", but when I test out the page, the anchor href attirubte looks like this: http://[server]/[route of current...

Submit button not posting on modal

javascript,c#,jquery,asp.net-mvc,asp.net-mvc-5
I have a form on a bootstrap modal with two buttons. This form is tied to an action named "DeleteWidgetConfirmed" I am trying to remove a widget from the database and from the front end, the panel gets removed from the front end but does not seem to get removed...

Perform wildcard search of all (displayed) model fields in MVC?

asp.net-mvc,oracle,linq,entity-framework,asp.net-mvc-5
I have an MVC5 View where I am using the Grid.MVC component (https://gridmvc.codeplex.com/). This allows me to easily display data from my Oracle DB and has out of the box functionality for Sorting/Filtering each Data Column. What I am trying to implement now is a Wildcard Search across all fields...

Two questions about MVC, and Identity

c#,razor,asp.net-mvc-5,asp.net-identity-2
I am very new to identity and MVC, I am trying to create an MVC app as one of my first projects. I have been able to follow a few tutorials and have successfully added additional properties to my ApplicationUser : IdentityUser class public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole,...

ASP MVC Application User Null using User.Identity.GetUserId

c#,asp.net,asp.net-mvc,entity-framework,asp.net-mvc-5
Ok so I have a relationship between the ApplicationUser and QuestionResults, my models are as below, the userId nor the UserName is retrieved, but I really need the UserId setup as a foreignKey on the QuestionResults entity. Any help is much appreciated the error that I am receiving is as...

object doesn´t contain a definition for Id

c#,linq,asp.net-mvc-5
Error: {"'object' does not contain a definition for 'Id'."} ViewModel public class PilotoVM { private FormulaEntities1 db = new FormulaEntities1(); public IQueryable<object> calcularValoracion() { return db.Piloto.GroupBy(p => p.id).Select(p => new { Id = p.Key, Valoracion = p.Sum( i=> i.agresividad + i.paciencia + i.reflejos + i.valentia + i.valentia)}); } } Controller...

MVC throwing HTTP 404 error

c#,asp.net-mvc-5
I am completely stuck and confused why it works with one View to Controller but not the other one. The one that works: public class HomeController : Controller { // GET: Home IAuthenticationManager Authentication { get { return HttpContext.GetOwinContext().Authentication; } } public ActionResult Index() { return View(); } [POST("login")] [ValidateAntiForgeryToken]...

Future plans to consider for asp.net mvc 5.2 web application, with releasing asp.net mvc6 (vnext)

asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-mvc-6,asp.net-mvc-5.2
I need to get any ideas of how i should be managing our previous asp.net MVC 5.2 web application.. now i am using asp.net mvc-5.2 with entity framework 6.0. and i want to start phase-2 for some of these projects. so should i consider upgrading my mvc 5.2 to be...

How to augment actionlink with route values at runtime with JavaScript in ASP.NET MVC 5?

javascript,asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-mvc-routing
I have this ActionLink. @Html.ActionLink("Link", "action", "controller", null, htmlAttributes: new {@class = "menuLink"}) I have to set routeValues to null because I don't know the value at compiletime. They are recieved from the selectedvalue of some dropdowns at runtime. Hence, I am trying to augment the routevalues at runtime with...

MVC 5 OWIN login with claims and AntiforgeryToken. Do I miss a ClaimsIdentity provider?

asp.net-mvc,asp.net-mvc-4,razor,asp.net-mvc-5,claims-based-identity
I'm trying to learn Claims for MVC 5 OWIN login. I try'ed to keep it as simple as possible. I started with the MVC template and inserted my claims code (see below). I get an error when I use the @Html.AntiForgeryToken() helper in the View. Error: A claim of type...

How to access UrlHelper.Action or similar from within Global asax

c#,routing,asp.net-mvc-5
I am trying to prepare a 301 redirect for a typo I made 'recieved' I am struggling to find a way of getting the url from the action and controller names. I am aware of UrlHelper.Action but it does not exist within Global.asax. How do I gain access to this...

Submitting the form always calls get action method instead of post action method

c#,asp.net-mvc,asp.net-mvc-5
Hi I've got the following code in my controller (asp.net 4.5.1 mvc 5) that allows a user to register on my site. Everything was working fine but Ive added another controller and another service and now when ever I try to register all it does on submit is redirect back...

EPPlus export model to Excel: System.NullReferenceException

c#,asp.net-mvc-5,epplus
I have an MVC view that correctly displays a model. Now that I have been asked to put an Export to Excel function on that page, I heard about EPPlus and gave it a try. From this site I thought I had something that would simply do the job. After...

EditorTemplates Where or Groupby on Questionnaire

asp.net-mvc-5,mvc-editor-templates,editortemplates
At the moment, I have a working prototype for a questionnaire with multiple questions and each question having multiple choices for an answer. Everything displays and saves great. However, I now would like to group the question/answers into 'sections' on my Edit view. I have tried a couple different methods...

In MVC how can I use the controller to render a partial view only for approved users?

c#,asp.net-mvc,asp.net-mvc-5
In MVC 5 I am attempting to use the controller to render a partial view only if the (Windows Authenticated) user belongs to one or more of a list of Active Directory groups. There are over 30 distinct groups I need to account for, so the "hello world" examples don't...

Entity Type 'AstNode' has no key defined

asp.net-mvc-5,ef-code-first,entity-framework-6
I'm porting a data model from EF4 to EF6 Code First. I'm getting the following message when the database creation is attempted. I'm at a loss to understand what is causing this. I don't have any Context, AstNode or JSParser entities. It is also not looking in the Models namespace:...

string.Format is not giving correct output when INR currency symbol (Rs.) come to display

c#,asp.net-mvc-5,devexpress
While display bank transaction data to INR currency symbol (Rs.), output is not coming correct way. I need to display currency symbol along with 2 decimal points with thousand separator. I have tried so far1: column.PropertiesEdit.DisplayFormatString = string.Format("{0} #,0.00", Model.CurrencySymbol); I have used DevExpress MVC GridView. Current output when INR...

What's the proper way to get data using Entity Framework so you can navigate through objects?

c#,asp.net-mvc-5,entity-framework-6
I have a .Net 4.5 MVC 5 database first project that I'm playing around with. There's a data access layer (Entity Framework 6), a business logic layer and the MVC layer. If I have an object with relationships in the data layer: namespace DataAccess { public class Course { public...

ASP.NET Vnext Tag Helpers for Areas

asp.net-mvc,razor,asp.net-mvc-5,tag-helpers
I may use <a href='/Area/Controller/action'> </a> in asp.net vnext but just want to know whether we can use tag helpers like <a asp-controller="ControllerName" asp-action="ActionName" asp-area="AreaName"> to redirect to the specific file in the area. Will any one guide me how to redirect to a file in area using tag helpers.?...

Add Object from razor to js list not working

javascript,c#,asp.net-mvc-5
i get this in chrome debug picsList.push(BL.datafuncs+pics); a string insted of picsList.push([{img:"",url:""}]); an object <script> var picsList = []; @foreach (var item in BL.datafuncs.GetMainPagePics()) { @:picsList.push(@item); } </script> public class pics { public string img { get; set; } public string url { get; set; } } public static List<pics>...

Are intranet sites vulnerable to CSRF?

asp.net,asp.net-mvc,razor,asp.net-mvc-5
I have developed and deployed an MVC5 .NET app which runs within an intranet and uses LDAP to authenticate users. Since MVC 5 gives you the @Html.Antiforgery() by default I used them in every from. However in production where the app is running in multiple nodes I'm having problems with...

How to use the same route with different parameter types?

asp.net-web-api,asp.net-mvc-5,asp.net-mvc-routing,web-api,asp.net-web-api-routing
I have an Api controller with two different actions that take different parameter types. // GET: users/sample%40email.com [Route("users/{emailAddress}")] public IHttpActionResult GetUser(string emailAddress) // GET: users/1D8F6B90-9BD9-4CDD-BABB-372242AD9960 [Route("users/{reference}")] public IHttpActionResult GetUserByReference(Guid reference) Problem is multiple actions are found matching when I make a request to either. Looking at other answers I thought...

Linq Conditional DefaultIfEmpty query filter

c#,linq,asp.net-mvc-5,linq-query-syntax
I have a query as below: bool variable = false//or true var query = from e in _repository.GetAll<Entity>() from u in e.Users where (e.AuditQuestionGroupId != null ? e.AuditQuestionGroupId : 0) == this.LoggedInEntity.AuditQuestionGroupId from p in e.PractitionerProfiles.DefaultIfEmpty() select new { entity = e, user = u, profile = p }; This...

MVC route attribute no controller

asp.net-mvc,asp.net-mvc-5,asp.net-mvc-routing
I'm building an intranet where I have the following home controller: [Route("{action=index}")] public class HomeController : Controller { public ActionResult Index() { return View(HomeModelBuilder.BuildHomeModel()); } public ActionResult FormsHome() { return View(HomeModelBuilder.BuildFormsHomeModel()); } } I'm trying to get my forms homepage to have a url of http://intranet/forms so I thought I...

Add azure db to mvc5 project

asp.net,azure,visual-studio-2013,asp.net-mvc-5,sql-azure
I have a MVC 5 project using visual studio 2013. How can I add/create a database in azure from visual studio so that EF6 code first can just use and create the models? I've been browsing server explorer but there is nothing there related to azure....

knockout.js with kendo UI MultiSelect over MVC 5

javascript,knockout.js,asp.net-mvc-5
Currently I have the following code, MVC with knockout bindings (this works fine) @Html.DropDownListFor(m => m.profiles, (SelectList)Model.profileItems, new { id = "ID", data_bind = "options: Profiles_msl, optionsText: 'profiles', optionsValue: 'ID'" }) I also have this which is kendo UI with MVC model bindings (no knockout). This also works. @(Html.Kendo().MultiSelect() .Name("Profiles")...

POST to MVC controller IEnumerable nested Model is null when I don't select checkboxes in order

c#,asp.net-mvc,razor,visual-studio-2013,asp.net-mvc-5
When I'm trying to get values in Post the values of checkboxes are set to NULL when I don't check then in order (1, 2, 3, etc). I need to select any of them in no order (i.e. 4, 5). MODEL: public class AssignUsersViewModel { [Display(Name = "Check to select")]...

How to migrate from SimpleMembership to ASP.NET.Identity

asp.net-mvc-4,asp.net-mvc-5,asp.net-identity,simplemembership
Migrating from MVC4 to MVC5 and want to use ASP.NET Identity too but I am struggling to find anything that covers everything I think I need to do to migrate the Identity. This link suggests all I need to do is create an ApplicationUser and migrate the data, and other...

MVC Validation on Subviews

asp.net-mvc-5,sitecore8
I am working on a Sitecore/MVC application, my first MVC application so I am learning as I go. No doubt I am going wrong somewhere along the line. I have a Basket that has 2 address views on it, one for billing and another for delivery. There is also a...

RedirectToAction when NullReferenceException of the Model is raised

asp.net-mvc,exception-handling,asp.net-mvc-5
I have the following controller method public ActionResult Details() { try { Pacient pacientdp = new Pacient(); if (pacientdp.PacientPrenume == null) { return RedirectToAction("Index", "Home"); } var id = WebSecurity.GetUserId(User.Identity.Name); MedicalDBContext pacientContext = new MedicalDBContext(); Pacient pacient = pacientContext.Pacients.FirstOrDefault(x => x.PacientID == id); return View(pacient); } catch (Exception ex) {...

403 Forbidden with Log4Net and MVC5

asp.net,asp.net-mvc,asp.net-mvc-5,log4net
So I followed this tutorial to add logging to my project. Locally everything works fine, but when I deploy it to my staging environment and try to even visit the root page of the site I get a 403.14 Forbidden error saying that I need to enable Directory Browsing. I...

Getting users from another AD Domain using PrincipalContext

c#,asp.net,active-directory,asp.net-mvc-5,active-directory-group
How would I get users from an AD Group which contains users from different domains. For example, I have 2 domains in my active directory, Domain1.corp.com and Domain2.corp.com I have an AD group called TestGroup which contains users from both the domains. Domain1 users: TestUser1, TestUser2 Domain2 users: TestUser3, TestUser4,...

How to define multiple partial Owin Startup classes and have them all run their code

asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-identity,owin
I'm working on an MVC application that will feature a "plugin" architecture. Basically there will be a main "host" project that will dynamically load other projects at runtime. We want to move all ASP.NET Identity related stuff into its own separate plugin project. The main host project already contains an...

ASP.NET MVC there's no mdf file anywhere… but my database still works?

sql-server,visual-studio,asp.net-mvc-5
My Website has two databases, one for user accounts and one for content. Both are created code first, and both have data in them. But I have only one mdf file in the project. The site works locally, the content gets displayed, I can edit and add to it, and...

MVC Calling a function from a partial view is not working

javascript,c#,jquery,asp.net-mvc,asp.net-mvc-5
This is my first MVC application, and this must be something simple but I've been trying to make this work for so many hours now.. What I want to do I want to display a table in a partial view and be able to delete items from the parent view....

How to fix the model to correctly use the MVC Foolproof library?

asp.net-mvc-5,foolproof-validation
I am trying to use MVC Foolproof library to validate my model and show error message respectively. However I am not applying the Data Annotation correctly so the validation does not works. My requirement is that I have two checkboxes and atleast one of them needs to be checked before...

Add/remove html markups according to the content of RenderBody()

c#,asp.net,asp.net-mvc,asp.net-mvc-5,razor-2
In my _Layout.cshtml: <section class="container content-section text-center"> @RenderBody() </section> I only want to have the "section" around when the "body" is not the home page. I was thinking of detecting url, but soon realized that I will have many Urls bound to the website, it's not the smart way to...

Redirect to action based on role not working. Maybe routing needed?

c#,asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-mvc-routing
I have the following controller public class GlobalAdminController : Controller { // GET: GlobalAdmin [AuthorizeUser(Roles = "admin")] public ActionResult Index() { return View(); } } And the home controller which is the main landing page for the app public ActionResult Index() { if(User.IsInRole("admin")) { RedirectToAction("Index", "GlobalAdmin"); } return View(); }...

How detailed should your repository be? Testing issues [closed]

c#,unit-testing,asp.net-mvc-5
In my controller, I have something like this: class HomeController { [AllowAnonymous] public ActionResult Index() { HomeViewModel viewModel = new HomeViewModel(); viewModel.FieldSearchCriteria = new SearchCriteria(); viewModel.Blogs = this.unitOfWork.BlogRepository.GetAllPublishedBlogs(1, 2, "PublishDate", SortDirection.DESC, null).ToList(); viewModel.FieldWanteds = this.unitOfWork.FieldWantedRepository.GetAllFieldWanteds( 1, 2, "CreatedAt", SortDirection.DESC, null ).ToList(); viewModel.Fields =...

show/hide elements dynamically using knockout

javascript,jquery,knockout.js,asp.net-mvc-5
I have a table which has four columns namely Code, Name, Quantity and Price. Out of these, I want to change the content/element of Quantity column dynamically. Normally, it should show the element with quantity displayed in it and when user click on element, I want to show the element...

Why is KnockoutJS not showing the same number of objects as my Web API controller?

knockout.js,asp.net-mvc-5,web-api
The solution was the same as in this question: How to get an observableArray's length? ...but the question itself is unique so anyone in the same situation will hopefully have an easier time finding the answer than I did. I'm fairly new to Knockout and to Web API. I've built...

less.modifyVars not working in Asp.Net MVC

c#,asp.net-mvc,asp.net-mvc-5,less,dotless
I have read this tutorial for working with Less in Asp.Net MVC5. To integrate LESS in ASP.NET MVC, I download and install the dotless NuGet package. And then added this bundle: var lessBundle = new Bundle("~/Less").Include("~/Content/Less/*.less"); lessBundle.Transforms.Add(new LessTransform()); lessBundle.Transforms.Add(new CssMinify()); bundles.Add(lessBundle); Here is the LessTransform: public class LessTransform : IBundleTransform...

Best approach to upgrade MVC3 web app to MVC5?

c#,.net,asp.net-mvc,asp.net-mvc-5
I have a web application which runs on Azure which is currently running MVC3/C#, EF6.1, .NET4.5. I would like to upgrade it to MVC5 to be: a) Current b) Get benefit of new features c) Get Performance gains. This is a part of a performance project, so hopefully there will...

Asp.Net MVC 5 + Bootstrap. How make inputs fit screen width?

css,asp.net,asp.net-mvc,twitter-bootstrap,asp.net-mvc-5
I really don't know what I'm doing wrong. I want my textboxes with same size of my buttons below. I already tried change a lot in the cshtml but without success. Below my cshtml file: @model SomeModel.Models.LoginViewModel <div class="row"> <div class="col-md-8 col-sm-12 col-xs-12"> <section id="loginForm"> @using (Html.BeginForm("Login", "Account", new {...

How to use more than 1 Model on a page by using asp.net mvc 5?

c#,razor,asp.net-mvc-5
I want to use 2 models. The first is on Index.cshtml page, and the second is on _Layout.cshtml page In the controller which contains the action public ActionResult Index(){...}, I declare some values and return it to View(). Like this: public ActionResult Index() { HomePageViewModel model = new HomePageViewModel(); //...

ASP.NET MVC 5 Set values for dropdownlist

c#,asp.net,asp.net-mvc,drop-down-menu,asp.net-mvc-5
I want to make a DropDownList with a numeric rating from 1-5. I have a rating model and I want to apply these dropdown values to WaitTime, Attentive and Outcome. Can I just set these values in the view and use the model? If so how would i go about...

MvcSiteMapProvider - Enhanced bootstrap dropdown menu

c#,twitter-bootstrap,asp.net-mvc-5,mvcsitemapprovider,mvcsitemap
I'm trying to build a menu like this: For reference I'm using this library https://github.com/behigh/bootstrap_dropdowns_enhancement @Html.MvcSiteMap().Menu("BootstrapMenuHelperModel") @model MenuHelperModel <nav class="navbar" role="navigation"> <div class="container-fluid menu-container"> <div class="collapse navbar-collapse"> <div class="navbar-header"> <span class="navbar-brand">FAR BACKOFFICE</span> </div> <ul class="nav nav-pills"> @foreach (var node in Model.Nodes) { if...

Convert SQL to linq statement

c#,linq,asp.net-mvc-5
I would like to convert the SQL syntax below to a linq statement to get a single boolean result back. The SQL is checking if a user exists in a current role. select case when exists (select 1 from Global.Application as a join Global.Role as r on a.ID = r.ApplicationId...

Updating ado.net entity data model without effecting model classes already in EDMX

c#,asp.net-mvc-5,ado.net-entity-data-model
i have done lot of attribute validation on Models in EDMX entity data model class .but the time of Updating by adding a new table the ado.net entity data model automatically removed all attributes which i given. Is there any way to update newly added table model class without effecting...

How to join two jquery methods into one statement?

jquery,twitter-bootstrap-3,asp.net-mvc-5
I am using jquery to display bootstrap modal and want to add custom message at runtime. Here is what I am doing? but wondering if there is a way to merge two lines into one:- $("#modalBody").append("saved successfully"); $("#modal").modal("show"); Bootstrap Modal:- <div id="modal" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div...