The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [asp.net-mvc-4]

ASP.NET MVC 4 is the fourth major version of the ASP.NET Model-View-Controller platform for web applications.

Filter by
Sorted by
Tagged with
29
votes
3answers
131k views

Update only modified fields in Entity Framework

I'm working on a website on ASP.NET MVC4 and EF5. I want to ensure that only modified values are updated in the database. I'm using a unit of work pattern and repositories for data work. Here's the ...
19
votes
1answer
15k views

Injecting AutoMapper profiles

I'd like to know if I'm doing profile configuration in the wrong place or in the wrong way. I'm following the Onion Architecture, so that restricts the direction of my dependencies towards the center....
18
votes
3answers
39k views

MVC Layered Project Structure

We are starting a new web project using C# / MVC4 and Entity Framework 5 for data access. I've decided to go with an n-layered approach for the structure of the project and I would like some feedback ...
17
votes
1answer
22k views

Using separate DBContext classes

I know that the DBContext represents a session (Unit-Of-Work and Repository) with the database, however I an unsure as to when I should have a different ...
17
votes
1answer
31k views

Following Repository Pattern properly

I am new to learning Repository Pattern. I am developing a site in MVC 4 (I'm new to it as well). The way I am using Repository pattern as follows: I created ...
12
votes
3answers
3k views

Tracking sports statistics

I am designing a new application to track sports statistics with code-first migration. I have the bare minimum POCO setup. The problem is that I am not happy with the design specifically how the ...
12
votes
1answer
7k views

Onion Architecture

After doing a whole bunch of research on Onion Architecture, I have made an attempt at implementing this in a new system that we are developing. We have the Layers as per below: Domain ...
11
votes
1answer
9k views

Generic ASP.NET MVC controller that generates many pages

I recently set out to create an open-source ASP.net MVC web development framework. Specifically, I wanted to automate some of the tasks associated with the creation of data-driven applications. I've ...
11
votes
1answer
3k views

Injecting SelectList objects into ViewData to enable using EditorFor on dropdown based properties

I have developed a system whereby I use an attribute to state which SelectList to use for an 'FK' property. I would appreciate some feedback mainly on by good ...
9
votes
1answer
9k views

Multi-checkbox validation

I wrote the following custom validation annotation for my project to confirm that at least one checkbox of a group of checkboxes is checked: ...
8
votes
2answers
13k views

Truncate port number from absolute Uri

We had a requirement to remove the port number from the Request.Url.AbsoluteUr i.e Actual: https://mysitename:443/Home/Index ...
8
votes
2answers
2k views

Accessing server side variables in views and JavaScript

I was a PHP developer and I started writing a product in C# without studying the basic structure. Now, I have around 100+ views with similar code. After 1 year into development, I now realize that ...
8
votes
2answers
12k views

DbSet<T> IncludeAll method

The Problem As an ASP.NET MVC4 developper, I'm using Entity Framework a lot. Considering performance I often use lazy loading for my models. ...
8
votes
1answer
3k views

Stock list view

I feel like using this many partial views where a view renders a partial that renders a partial is just digging a hole of poor design, so I'm looking for any suggestions or guidance as to if this is ...
7
votes
3answers
757 views

Ternary extension method

I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup. Is there a better way to write this ...
7
votes
2answers
2k views

ASP.NET MVC to produce a repair invoice

I just started working with ASP.NET MVC a few weeks ago, and I'm finding that it can be very easy to write spaghetti code in the controllers. For my first project, I created a very simple view with a ...
7
votes
1answer
18k views

Custom System.Web.Http.AuthorizeAttribute

I've hacked together what feels like a mess for an authorize attribute to secure web api methods. The code appears to be functionally correct; passing the unit tests in place. The code has me worried ...
7
votes
1answer
11k views

Passing a selectlist to the view based on database models from viewmodel is a MVC anti-pattern

We need to select a model reference from a view. To do this we need to add a dropdownlistfor. This is based on a selectlist containing database models. passing selectlists by viewbag This solves our ...
7
votes
1answer
90 views

Retrieving all institutions in a specified country

I'm checking each variable to prevent null exception, but still wondering can this be improve in much simpler and cleaner if you will be writing the same code? Please see the below snippet: ...
7
votes
1answer
172 views

Customized Template Login

While the MVC4 template provided by Microsoft is useful, I feel there are a few scenarios that should be covered to help out users trying to log in. Allow the user to log in with their email address ...
7
votes
1answer
5k views

AutoFac, NHibernate & ASP.NET Web API integration

I've recently been learning (and struggling with) integrating AutoFac, NHibernate & ASP.NET Web API. I have found several tutorials with code that did not work as anticipated but managed to ...
6
votes
3answers
20k views

Configure AspNet.Identity to allow for either username OR email address on login

I am wondering if there is a more efficient route to take here. Using AspNet.Identity I would like to allow the user to sign in to the same text box using either ...
6
votes
2answers
12k views

Building a better Data Access Layer Class

Since I am new to MVC and the Entity Framework, I have been struggling to grasp the concept of creating useful Data and Service layers. I have come across a scenario where I believe my code has become ...
6
votes
1answer
13k views

Entity Framework using Repository Pattern, Unit of Work and Unity - viable approach?

Using a combination provided from this example and this implementation, I'm creating a solution that decouples the UnitOfWork class from the individual repositories,...
6
votes
1answer
256 views

PBKDF2 authorization

I've discovered that using hashed passwords with salts is a much better idea than MD5/SHA256, so I'm not hashing them with PBKDF2. However, I'm wondering if this is a correct approach to authorizing ...
6
votes
1answer
9k views

ListBox for a many-to-many relationship

I'm looking for a good and easy to use solution for creating MultiSelectLists in MVC for many-to-many relationships. I have this following example code and it works fine, but it just takes a lot of ...
6
votes
1answer
131 views

MVC4 approach to checking authorization after POST

I have a very simple form that is designed to update account expiration dates. I'm currently creating a View Model and sending that to the form, however, I still have to pass along a GUID so I know ...
6
votes
1answer
5k views

Unit of work, Ninject, Repository and WebAPI implementation

After recently getting a bulk of work done on my WebAPI service layer, I thought I'd post some of my working on here for you guys to tear apart, generally, most of it 'feels' mostly okay, but I know ...
5
votes
3answers
520 views

Recording error messages from an exception

How do I shorten these if else statements? As you can see, those elses are repeated. ...
5
votes
3answers
5k views

Calculating total sales from each member

I am building a new system that is using some tables from an old system. For each user on this new system, I need to go to the old system and total up their sales. Currently it takes between 2-5 ...
5
votes
1answer
8k views

Unit of Work with Repository Pattern MVC 5 & EF 6

I put together a sample of how I am using the Unit of Work & Repository pattern based on my understanding. Can anyone please let me know if I am implementing this the correct way? If I am not, how ...
5
votes
2answers
993 views

PreWarmCache for MVC Application with Stopwatch Infinite Loop

I used the information from the article "Auto-Start ASP.NET Applications (VS 2010 and .NET 4.0 Series)" to create a background task that runs on an infinite loop. Ultimately, this program is going to ...
5
votes
1answer
2k views

Implementation Async/Await

I have a simple ASP.NET Web API project. Now I want to make all basic methods as asynchronous. I tried to do something, and it's working but I'm not sure that it was implemented properly. Please ...
5
votes
1answer
2k views

Model Design for MVC4 Applications using Entity Framework Code First

I would like to put the following design to your consideration. This is the pattern I use to follow when I'm building a Model and Data Access Layer for an MVC Application (using Entity Framework 5). I'...
5
votes
1answer
15k views

Select list items in ViewModel fetched using a Repository

Doing database access in ViewModel is generally considered a bad practice. However, when you have a <select> in your view, you need to populate it using the ...
5
votes
1answer
373 views

MVC4 Routes, using Default

Should I leave the Default Route in if it's not adding any benefit? I have a RouteConfig.cs file that looks like this: ...
5
votes
1answer
5k views

Where to put hidden fields when displaying entities properties in a table?

Let's say that I have a view, whose purpose is to show a table with some information about a person entity. The view contains a form with an input element that the user can use to add a new person to ...
4
votes
2answers
151 views

Return existing values inside database

Here's a method inside my controller that reads the values of angle and point data from my database. Then it grabs the data and adds it to a new list and sends the JSON to the view. I can't simplify ...
4
votes
4answers
1k views

Instantiating if null

I often have static classes which uses the DataContext somehow, and they all make a new DataContext, but often I already have ...
4
votes
2answers
9k views

Using a recurring System.Threading.Timer in an Mvc Application

I'd like your opinion on something. I have the following class: ...
4
votes
1answer
9k views

Listing users in Azure Active Directory

The code below is the Index Action from a User Controllers. Basically this code returns a list of users from Azure Active Directory using Azure Authentication Library (ADAL). However I need to show ...
4
votes
1answer
86 views

Post Service Class

I have one entity that depends on another however in my API service class I would like to just deal with the dependent entity. Am I doing this correctly and is there a better way to go about this? ...
4
votes
2answers
119 views

Eager load additional data about some instructors

Below is a snippet of code of a little practice project. I am still pretty new to EF and I was wondering if there is a way to write the below statement so that all required data is eager loaded since ...
4
votes
1answer
2k views

Using readonly input fields to persist data between views

I'm building a multi-screen Ajax form in an ASP.NET MVC solution. The first screen displays some user details. If the user clicks 'edit', they are taken to the next screen where they can edit the ...
4
votes
1answer
593 views

FormBuilder Code Make More Genereic

I want to construct a form builder for an internal project in mvc4. I am using partial views to load the various controls. However I feel that having ten or 20 action-results in my HomeController ...
3
votes
4answers
189 views

Setting new lines and adding them to a list to be drawn

I have a method that basically passes in a known drawn line segment in my view and then draws parallel lines n distances away from the passed in original line. This one in particular draws two ...
3
votes
4answers
371 views

Website news message edit panel

The explanation I'm making a website for a hypothetical theatre to get a better feel of MVC web-applications in ASP.net. The idea is that there are newsmessages that are displayed on the homepage, ...
3
votes
3answers
9k views

Entity Framework with multiple connections open?

I'm learning Entity Framework and I'm wondering if this code is the proper way of doing this. Basically this is my attempt at refactoring a very long controller in ASP.Net MVC 4. I'm using Entity ...
3
votes
2answers
687 views

Refactor MVC project's classes and methods

I'm learning C# as a web developer rather than a C# developer learning web development. I've gotten the hang of creating models and controllers (or so I think) for a web project, and I've read some ...
3
votes
1answer
408 views

N-tiered web app to save a role

My project manager is saying that there are many bad things in my code, but they are not helping me to correct it. Can you please specify the bad things they mean? I have 7 projects in my solution ...