Questions tagged [asp.net-mvc]

Model-View-Controller for the ASP.NET framework

Filter by
Sorted by
Tagged with
0 votes
1 answer
3k views

Copying properties between two classes

I have an ASP.NET MVC 5 app and I map properties between model and viewmodel and vice versa. I could use automapper to do this but since I don't need mapping rules to convince me to use it as I ...
devfric's user avatar
  • 133
2 votes
0 answers
136 views

Business logic in controller

Led by the recently read premise "Lean controllers and fat models" I've come to the conclusion that my controller might be too fat at the moment. Basically, what I'm trying to achieve is simple Edit ...
wegelagerer's user avatar
3 votes
3 answers
7k views

Master detail INSERT in Entity Framework 6 Database First MVC 5

I have a DB with a master table called "facturas" and another detail table "facturas_detalle." I would like to insert to them, so this is a "Database-First". I need some guidance or advise of best ...
Mr_LinDowsMac's user avatar
1 vote
2 answers
867 views

Implementing Search method For a Class

In my web app, I have a view where users can search in receipts and drafts. I've implemented this ability in search method at my view model, but I'm not sure if this is the best place to put it. So I'...
Akbari's user avatar
  • 179
6 votes
1 answer
7k views

Checking locked users using Identity 2.0

I'm writing a theoretical MVC application to aid in learning more about ASP Identity 2. In real terms I'm new to ASP Identity as a whole but thought I'd jump in in this release as it's the default ...
paulpitchford's user avatar
1 vote
1 answer
1k views

Adding a link on page with current URL (including hash) in a querystring

I'm trying to add a link to a page. The link should contain the current URL in a querystring (to be used as a ReturnUrl) and it can contain a hash. Middle-...
thomius's user avatar
  • 113
5 votes
2 answers
124 views

Writing a thin navigation controller

I'm trying to achieve a thin controller, and I started out with a thin controller but over time as the project has progressed the controller has got more complex. Could you please review the following ...
Professor of programming's user avatar
6 votes
1 answer
120 views

Highlight Current Link

I'm using this technique for highlighting current links (e.g. how the "Questions" link is highlighted on this very page you're looking at). I changed the code a little bit and came up with this ...
Sirwan Afifi's user avatar
4 votes
1 answer
2k views

Choose the right type for method GetById

I designed my repository class and I need some advice from you. Now I have a method GetByID that returns a generic type: ...
Roman Marusyk's user avatar
2 votes
1 answer
828 views

Method that return related entities using OData

There is method GetFull that should use OData return related entities. When I call GetFull(12, "entity1,entity2") then I will ...
Roman Marusyk's user avatar
1 vote
2 answers
222 views

Getting a user's property

Can this extension method be improved? ...
Sirwan Afifi's user avatar
3 votes
1 answer
2k views

WebApi action that updates entity using stored procedure

I have ASP.NET WebApi project. Some of controller has method SetAsMain(int id) that get information about people then use stored procedure update people. How can I ...
Roman Marusyk's user avatar
3 votes
1 answer
7k views

Run stored procedure from repository using EF

I need to dynamically call a stored procedures from my repository, and here is a my implementation: ...
Roman Marusyk's user avatar
6 votes
2 answers
213 views

Storing an integer counter in indexer

I've been implementing a custom internal server error page in ASP.Net MVC which will check if the current user is either an administrator or accessing the page from localhost, and if so, show them a ...
MrLore's user avatar
  • 1,358
7 votes
1 answer
5k views

Helper for DropDownLists with extension method

Is the following helper idiomatic ASP.NET MVC? All the built-in DropDownListFor helpers only accept ...
sshine's user avatar
  • 741
6 votes
3 answers
4k views

Monkeying around with Survey Monkey and Asp.Net Mvc

Intro I've been a desktop dev for a long time now, and have never really had to monkey with web development until very recently. I have a need to do some custom integration with Survey Monkey's Api ...
RubberDuck's user avatar
  • 30.8k
5 votes
4 answers
2k views

Generic Repository For Web Apps

I was developing a web app using Entity Framework 6 and MVC 5. For the data access layer, I eased the job and wrote a generic repository as following: ...
Akbari's user avatar
  • 179
1 vote
3 answers
2k views

Partial view for frequently used drop down lists

I have one input that is needed in many forms, so I created a partial view for that. In the partial view I query the database and generate a drop down list. I just want to make sure, this is the best ...
Akbari's user avatar
  • 179
3 votes
2 answers
2k views

MVC-Web API 2 integration

For the first time ever, I'm integrating an MVC website to an ASP.NET Web API 2 web service (both of which are coded by myself). I'd appreciate it if you can just look this over for me and let me ...
Ortund's user avatar
  • 521
2 votes
2 answers
3k views

Basic survey app

I am learning MVC 5 .NET and this is a bit different than Rails activerecord when creating relations. I have created a basic survey app that has a Survey class and this relates to the questions and ...
thefenry's user avatar
5 votes
1 answer
2k views

N-Layer using MEF dependency injection on MVC project

I'm trying to create a "perfect" generic solution structure for MVC (5.2.3.0) projects using MEF. Currently my solution looks like this. Core layer contains generic classes that could be used in any ...
BrunoLM's user avatar
  • 183
3 votes
1 answer
910 views

Including functions in _ViewStart.cshtml

I've got the following code in my _ViewStart.cshtml file: ...
Professor of programming's user avatar
3 votes
2 answers
6k views

Checking for user permissions

The idea here is we have Roles, Permissions, and a table called PermissionRoles that connect the two. So a Permissions can be in many Roles, and many Permissions can have the same Role. So what the ...
barnacle.m's user avatar
3 votes
2 answers
199 views

MVC refactoring parameter check

I had this code repeated in many Actions: ...
woggles's user avatar
  • 133
1 vote
1 answer
798 views

Method that checks whether to disable or enable the buttons depending on whether data is null or not

I have this bit of code that needs refactoring/simplification. The below grabs the planning data for view A and B. Then it joins the planning and matching image for view details. So then it determines ...
Kala J's user avatar
  • 542
5 votes
1 answer
3k views

Pagination implementation for a blog system

Last night I was working on a project that I've embarked upon as a learning exercise. I decided to add a pagination feature to my blog system. I made an attempt at it and got close... but I decided to ...
Dan Beaulieu's user avatar
5 votes
1 answer
4k views

Is it an anti-pattern to let ViewModel fill itself from a domain object? [closed]

Let's say you have a Employees table mapped to a Employee class. Now you want to code a Edit page for general information. You need a ViewModel with all the properties you need to build the page, so ...
Pluc's user avatar
  • 161
1 vote
2 answers
311 views

Code separation in MVC

Firstly I am not a professional programmer and I am just learning C#, MVC and Web Development. Much of what I describe here is self taught and comes from lots of googling and posts on Stack Overflow. ...
cramar's user avatar
  • 11
2 votes
2 answers
4k views

MVC N-Tier Architecture

I am working on a new MVC web application, so the project is in early stages. I have created 4 projects. Let me explain what they do: Common --> contains all my DTOs, enums helpers, ViewModels ...
Dawood Awan's user avatar
1 vote
1 answer
1k views

Check if modelitem refers to currently logged in user with mvc identity

I'm using MVC in order to generate a couple of views within my webpage. For a way of logging in, I've decided to use Asp.net's Identity, which I am very happy with. However, I'm trying to find an ...
jbutler483's user avatar
1 vote
1 answer
784 views

Using ASP.NET identity in a new app

I need code review for using ASP.NET Identity in a new app. Goals: Use int instead of GUID for IDs. Separate identity from view layer I need code review if I did ...
1110's user avatar
  • 217
2 votes
1 answer
4k views

Adding data to the DB in EF without using navigation properties

Questions: Is there a better way other than assigning IDs manually and creating separate lists for each model the way I have? (for this particular scenario). If so, how? (Still taking the conditions ...
mdc's user avatar
  • 123
7 votes
2 answers
2k views

ViewModel creator design

I am trying to move some logic outside my controller for creating my view models for the view. I have a lot of queries to fire to make sure the complete view model is ready, so to keep my ...
janhartmann's user avatar
1 vote
1 answer
1k views

Dependency Injection With Unity in MVC 5 without repository and unit of work

I want to use dependency injection with Unity in my application. I am not following repository pattern and unit-of-work (and don't want to). I also have ViewModel in my controller action method. ...
koushik's user avatar
  • 121
4 votes
1 answer
326 views

Handling CRUD for look-up tables

I'm creating the admin portion of a project. Specifically, I am wanting to allow the users to update the look-up tables for their areas of interest. All of my look-up tables have the same structure: ...
EZE's user avatar
  • 51
5 votes
2 answers
215 views

Use of Model and View (MVC)

I have an application using c# and MVC5, with RazorEngine. My application manages requests (orders from clients) and I need to show them in tables. To achieve this I have a Controller (...
Flame_Phoenix's user avatar
5 votes
2 answers
910 views

Abstracting a Password Service

I want to use Microsoft.AspNet.Identity's PasswordHasher but I don't want to pollute my Domain layer with knowledge of it. As ...
dav_i's user avatar
  • 226
5 votes
3 answers
4k views

Returning a validation error from a command handler

...
User 12345678's user avatar
4 votes
2 answers
2k views

Refactoring IEnumerable<ValidationResult>

I have the below code which increases the code complexity. Any way to refactor it? I am trying to refactor the below code so that the CCM can be reduced for the code. i.e code complexity matrix. <...
user avatar
3 votes
1 answer
189 views

Null checks in view

It's really a nitty-gritty issue for me, and I have been here many times before. How could this be improved? I have a basic viewmodel for a view: ...
user3633222's user avatar
3 votes
3 answers
585 views

Code optimization by constant if-structure iteration removal

Below you will find the specific code that I am attempting to optimize. I have a method previous to called getCount() which, based on similar parameters as below, ...
Bialy R Bert's user avatar
3 votes
3 answers
176 views

Account inactivity reminder

I wanted to know if this is the best approach for the Single Responsibility Principle. The responsibility of this class is to remind users whose accounts are about to expire due to inactivity. On the ...
DavidJS's user avatar
  • 191
4 votes
5 answers
10k views

Checking dictionary for specified key

The first part of code is for me very unreadable. I tried to write in another way but I'm open to your suggestion! ...
Revious's user avatar
  • 503
4 votes
2 answers
12k views

Is it "legit" to use a Linq query in a razor view?

I have a Linq query in my razor view like below. Its just getting contacts that belong in the group. ...
smarble's user avatar
  • 143
3 votes
1 answer
5k views

Insert missing records in a list with LINQ

We have a table with periods, and other child tables with these periods and values for combinations of product + location. Based on selected periods, I would like to add any missing rows in the child ...
Randeep Singh's user avatar
5 votes
1 answer
3k 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 ...
Matthew Dresser's user avatar
15 votes
2 answers
39k views

Unit of work + repository + service layer with dependency injection

I am designing a web application and a windows service and want to use the unit of work + repository layer in conjunction with a service layer, and I am having some trouble putting it all together so ...
Guillermo Gomez's user avatar
2 votes
1 answer
31k views

LINQ query using StartsWith and Contains to limit the results for an autocomplete field

As a source for a jquery-ui autocomplete field, I've written this action: ...
Ivo Coumans's user avatar
23 votes
3 answers
13k views

Returning status codes from business layer

This is what I've been doing so far in my business layer to return error messages to the user. ...
ThunderDev's user avatar
1 vote
1 answer
574 views

Model binding with a ViewModel

I have two ViewModels with the one referencing the other: ...
user avatar