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
2
votes
2answers
114 views

Open closed principle in a method

I have an ASP.NET MVC project wherein I need to follow the open closed principles. The project converts a .csv file to a model from a database, but in the future we might also have to convert Excel ...
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. ...
2
votes
1answer
140 views

Use of C# Razor Syntax in MVC.net view

I have the code below and I am looking for input as to how I can improve it. The main question here is should the code at the top in razor brackets be moved to the Controller and returned via a ...
1
vote
0answers
37 views

Cancelling long running operation in MVC4

I have been wondering if the way I have implemented cancellation of a long-running import operation is correct. My questions are: Did I handle cancellation correctly? Is it ok to pass the ...
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: ...
2
votes
2answers
15k views

Calling Web API from MVC generic way of approach

Our Project architecture is AngularJS + MVC + WebAPI. Angular JS would call MVC action and MVC action further calls API methods. Below are some of the action methods we used for calling api methods. ...
1
vote
1answer
13k views

Passing model to _layout.cshtml

I have login page that looks like: It has a ViewModelBase and a ViewModel as: ...
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, ...
1
vote
1answer
279 views

Defining application flow in ASP.NET MVC5

Currently I am assigned to a project which has a standard view-flow, yet this flow is determined by whether settings are set to either true or false. So, for example, let the standard flow be ...
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 ...
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 ...
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 ...
2
votes
2answers
90 views

Grab set of data from database that matches userid and return it to the view

I want to get the row of data that matches the user ID I have. Then I want to return that view to my view to be displayed in my textboxes for editing. Here's the action that gets called when a get ...
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 ...
2
votes
2answers
1k views

Selecting security questions and entering answers

I have a dialog that houses 6 security questions and 6 security question answers. I want to pass the data the user selects and enters from the view to the controller to save the data in session. ...
3
votes
1answer
283 views

Razor view to render simple scaffolding for complex type

After several attempts to follow my intuition that this code can be refactored to something more DRY, I keep hitting road blocks. Hoping someone can see a refactor that might get me going in a nicer ...
3
votes
4answers
186 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 ...
2
votes
2answers
5k views

Reading data from database, saving to new list and adding list to grid

I made some changes to how I was saving the data in order for it to show up on a kendo grid. Right now my giant method is getting data from the database (using ...
3
votes
1answer
68 views

Changing a div that contains a view link

I've written some code to load a section of my application between views. While my code works, I'm wondering if there is a better way to do it. (partial views perhaps?) I currently load the views, ...
3
votes
2answers
123 views

Removing nested for loops to hasten API call response time

I've got an MVC APU project that I'm working on to feed data to some JavaScript charts. This beast below takes nearly 1 second of server time to process before it is served to the chart. I know that ...
3
votes
2answers
374 views

MVC4 Unit Of Work with Entity FrameWork

I am designing a new asp.net MVC4 application. I know that context class generated by EF is Unit of work and Dbset is the repository class. I am just avoiding the extra abstraction. I want to know ...
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 ...
1
vote
1answer
315 views

LINQ to Entities query of tests for my classes, with many subqueries

This MVC4 controller method, which uses EF6, is taking a long time to run (over 2 seconds). I've added verbose comments for the purpose of this post only. ...
2
votes
1answer
599 views

Approach to MVC 4 windows group security to enable/disable controls in view

There are 3 window groups to add users and the application uses MVC 4. Here's my approach to add security attributes to my controllers and pass user's role to the view in order to enable/disable ...
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 ...
4
votes
2answers
117 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 ...
0
votes
2answers
718 views

Questionnaire design puzzle

I am designing a small questionnaire web service application but however I would like if someone can look at my design and see if it good approach I am taking. The application has the following ...
3
votes
1answer
4k views

Handling conditional logic inside controller actions

I am looking for best practice in handling conditions inside the controller actions in ASP.NET MVC: ...
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: ...
3
votes
1answer
1k views

Quiz form website

I'm trying to get a good grasp on ASP.Net MVC, Razor and RadioButtons, so I tried to make a quiz to test my skills. I implemented a working quiz form in the following way in Razor (not posting the ...
3
votes
1answer
515 views

Is there currently anything wrong with my custom authentication and authorization?

I have my reasons not to use the ASP.NET membership. Though this causes me some issues. I read about a thousand articles on ASP.NET MVC custom authentication and I've found that almost all of them are ...
0
votes
2answers
4k views

Safe DbContext Disposal

I have a service class called ClientService, the service class is called using an interface IClientService. The service class ...
1
vote
2answers
992 views

Confusion over using generics in MVC project

Consider the following: Remote service accepts SecondAction=Search and SecondAction=Update. For ...
3
votes
2answers
683 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 ...
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
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? ...
6
votes
3answers
19k 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 ...
2
votes
1answer
158 views

Admin class for monitoring blog users

I have an admin class that controls when a user logs in and creates a new blog post. I am wondering if there is anything I can do to improve this class. Is there any way to reduce the code? Is there ...
2
votes
1answer
1k views

Extending the MVC Routecollection

I'm currently developping an MVC framework on which I will be writing my websites. This is done through the usage of a starter kit. In standard MVC, your routes are registered like the following: <...
3
votes
1answer
3k views

Updating Related Data the MVC/EF Way

I have an ASP.NET MVC Controller, the relevant parts of which appear here: ...
2
votes
2answers
828 views

ASP.NET MVC return early from an action that returns a model

Consider the following code segment written by a coworker of mine: ...
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
2answers
2k views

Multiple loops versus multiple stringbuilders

I've come across the following piece of code in a Razor view ...
5
votes
2answers
984 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 ...
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 ...
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 ...
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
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'...
1
vote
1answer
193 views

Class to Return Single Integer

I have a class used to return a single integer, but think there is room for improvement. The class should only return a single row every time and if no row is found it might be a good idea to throw an ...
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 ...