All Questions

Tagged with
Filter by
Sorted by
Tagged with
386 votes
10 answers
365k views

Ignore mapping one property with Automapper

I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with: Mapper.CreateMap<...
Msam85's user avatar
  • 4,104
195 votes
11 answers
435k views

Accessing MVC's model property from Javascript

I have the following model which is wrapped in my view model public class FloorPlanSettingsModel { public int Id { get; set; } public int? MainFloorPlanId { get; set; } public string ...
Null Reference's user avatar
141 votes
8 answers
153k views

ASP.NET MVC Yes/No Radio Buttons with Strongly Bound Model MVC

Does anyone know how to bind a Yes/No radio button to a boolean property of a Strongly Typed Model in ASP.NET MVC. Model public class MyClass { public bool Blah { get; set; } } View <%@ ...
brianstewey's user avatar
  • 1,792
94 votes
5 answers
39k views

DisplayNameFor() From List<Object> in Model

I believe this is pretty simple, I just can't seem to find the right way to show the display name for an item within a list within my model. My simplified model: public class PersonViewModel { ...
Jonesopolis's user avatar
  • 25.2k
65 votes
4 answers
122k views

Email model validation with DataAnnotations and DataType

I have following model: public class FormularModel { [Required] public string Position { get; set; } [Required] [DataType(DataType.EmailAddress)] public string Email { get; set; } ...
lifeofbenschi's user avatar
64 votes
11 answers
22k views

Custom tag helper not working

I followed a few guides on creating a custom tag helper for ASP Core. This is my helper: using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using System; ...
Matthew Goulart's user avatar
44 votes
4 answers
138k views

MVC 4 - how do I pass model data to a partial view?

I'm building a profile page that will have a number of sections that relate to a particular model (Tenant) - AboutMe, MyPreferences - those kind of things. Each one of those sections is going to be a ...
MattSull's user avatar
  • 5,554
30 votes
5 answers
49k views

MVC Validation Lower/Higher than other value

How is the best way to validate a model in MVC.Net where I want to accept a minimum/maximum. Not individual min/max values for a field. But separate fields for a user to specify a minimum/maximum. ...
Ben Ford's user avatar
  • 1,364
28 votes
3 answers
20k views

Should I use an int or a long for the primary key in an entity framework model

I am writing an MVC5 Internet application and I have a question about the id field for a model. Should I use an int or a long for the id in a model? I am talking about the field that is used for the ...
Simon's user avatar
  • 8,219
26 votes
4 answers
24k views

How to validate only part of the model in ASP .NET MVC?

I have a large model (large I mean model class contains a lot of fields/properties and each has at least one validation attribute (such as Required, MaxLength, MinLength etc)). Instead of creating one ...
Dmytro's user avatar
  • 17k
25 votes
5 answers
18k views

How to set view model on ViewResult in request filter?

I make a MVC project and I want set Model into View from filter. But I do not kown ,How can I do this. the Model: public class TestModel { public int ID { get; set; } public string Name { ...
zt9788's user avatar
  • 958
21 votes
2 answers
13k views

Check if Model is valid outside of Controller

I have a helper class that is passed an array of values that is then passed to a new class from my Model. How do I verify that all the values given to this class are valid? In other words, how do I ...
James Santiago's user avatar
20 votes
4 answers
31k views

Compare two lists of object for new, changed, updated on a specific property

I've been trying and failing for a while to find a solution to compare to lists of objects based on a property of the objects. I've read other similar solutions but they were either not suitable (or I ...
user3313496's user avatar
18 votes
3 answers
22k views

Passing a model object to a RedirectToAction without polluting the URL?

Here's what I'm trying to do: public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(ContactModel model) { if (ModelState.IsValid) { // Send email ...
sergserg's user avatar
  • 22k
18 votes
7 answers
45k views

Access a Model property in a javascript file?

Is it possible to access a Model property in an external Javascript file? e.g. In "somescript.js" file var currency = '@Model.Currency'; alert(currency); On my View <script src="../../Scripts/...
BlueChippy's user avatar
  • 6,021
17 votes
3 answers
59k views

pass two models to view [duplicate]

I am new to mvc and try to learn it by doing a small project with it. I have a page which is supposed to display that specific date's currencies and weather. so I should pass currencies model and ...
Arif YILMAZ's user avatar
  • 5,796
17 votes
4 answers
15k views

asp web api patch implementation

Assume i have this model public partial class Todo { public int id { get; set; } public string content { get; set; } public bool done { get; set; } } And i send this as json data to my ...
Willem D'Haeseleer's user avatar
17 votes
4 answers
21k views

@Html.EditorFor DateTime not displaying when set a default value to it

I'd like to set a default value to my model in Controller, But It cannot display in create page. TestModel code: public class TestModel { [DataType(DataType.DateTime), Required] [...
Sue Su's user avatar
  • 311
15 votes
3 answers
28k views

RequiredIf Conditional Validation for two variables in MVC4

I have a model class that is following public bool Saturday{ get; set; } public bool Sunday{ get; set; } public string Holiday{ get; set; } In which I want to use the RequiredIf condition for ...
Md Aslam's user avatar
  • 1,338
15 votes
3 answers
11k views

Where to put ViewModel classes in MVC

My question is very simple. I want to know where to put my ViewModels in an MVC application. Currently the project I'm working on only has ViewModels and they are stored in the Models folder. In that ...
Vivendi's user avatar
  • 20.6k
14 votes
2 answers
31k views

How do I map checkboxes onto MVC model members?

I have an MVC view <%@ Page Language="C#" MasterPageFile="PathToMaster" Inherits="System.Web.Mvc.ViewPage<ModelData>" %> and I have a form with HTML markup for a set of checkboxes: <...
sharptooth's user avatar
  • 169k
14 votes
2 answers
29k views

Validation best practice for Model and ViewModel

I have separate model and viewmodel classes. Where viewmodel classes only do UI level validation (refer: Validation: Model or ViewModel). I can verify on post action in a controller that model (...
Yahya's user avatar
  • 3,406
14 votes
4 answers
9k views

How to set your sensitive data in the application code when creating ADO.NET Model?d some tag a

I am creating a model for a database and was curious at the following statement in the ADO.NET Entity Model wizard where you have the options of choosing Yes or No as where to store sensitive data - ...
Donald N. Mafa's user avatar
13 votes
4 answers
25k views

MVC Error: The model item passed into the dictionary is null

I'm just trying to build a view but I'm getting the following error: System.InvalidOperationException: The model item passed into the dictionary is null, but this dictionary requires a non-...
109221793's user avatar
  • 16.6k
12 votes
4 answers
2k views

MVVM: Thin ViewModels and Rich Models

I'm continuing to struggle with the MVVM pattern and, in attempting to create a practical design for a small/medium project, have run into a number of challenges. One of these challenges is figuring ...
11 votes
3 answers
16k views

MVC 2 - Data Annotation for Label?

Is there an annotation to set the Label-name of the property? Ex: public class MyModel { [LabelName("Your Phone")] public string Phone{get;set;} } Thanks And then in the view, it would show the ...
WoF_Angel's user avatar
  • 2,579
10 votes
1 answer
6k views

Custom Data Annotations ASP.NET MVC C#

I have the follwing question about MVC 2 with C#. Here is my Model: public class Pmjob { [Tooltext="Hier soll der Name eingegeben werden"] [DisplayName("Type")] public int Name { get; set; }...
Stefan aus Linz oida's user avatar
10 votes
1 answer
17k views

How do I use Html.EditorFor to render radio buttons in MVC3?

Here's my model: [Required] [Display(Name = "I'm a:")] public bool Sex { get; set; } And my editor template: <div> @Html.LabelFor(model => model.RegisterModel.Sex) @Html....
Only Bolivian Here's user avatar
9 votes
1 answer
15k views

Model binding with nested child models and PartialViews in ASP.NET MVC

I have the following types and classes: namespace MVC.Models public class Page { public EditableContent Content {get; set; } } public class EditableContent { public TemplateSection ...
MartinHN's user avatar
  • 19.7k
9 votes
2 answers
6k views

Why do we no longer need to manually validate models in higher versions of ASP.NET Core?

All my models are automatically validated before hitting the endpoint, and return appropriate errors if some form of validation has failed. I remember back in ASP.NET Core 2.2 we needed to manually ...
SpiritBob's user avatar
  • 2,494
9 votes
5 answers
7k views

In which class should I load my data when using MVVM

I'm currently learning C#, and recently I've learned about the MVVM design pattern for WPF. I am writing a simple program as a way to practice this, but I'm not sure where I should write the method ...
user184994's user avatar
  • 18.1k
9 votes
2 answers
6k views

Using a ASP .NET MVC model value to validate another model value?

I have a model class like this: public class SomeClass { public int EmployeeId {get;set;} public int DayTotal {get;set} } For this model class I am creating a custom ValidationAttribute for ...
John M's user avatar
  • 14.5k
8 votes
2 answers
22k views

.NET Data Model is shown as XML and not as Diagram

That is. I format my computer and install the entire enviroment again, but I can't see the data model diagram. I mean, I open the data model (edmx file) and I see all the DB tables and DB information ...
Faabass's user avatar
  • 1,124
8 votes
1 answer
12k views

Enum to Checkboxes in the Model C# MVC4

Now I was looking to make some validation for some checkbox fields in my model. I want to create a unique rule that would require at least one checkbox to be true (or checked) in each category to ...
1011 1110's user avatar
  • 763
8 votes
3 answers
810 views

How many models of Asynchronous development in .NET?

I am learning asynchronous programming using C# and I usually use BeginInvoke, but I am not very sure about the other methods of creating asynchronous application. I have asked a question about this,...
CharlieShi's user avatar
8 votes
3 answers
3k views

"EntityType has no key defined" exception although key is defined with HasKey

Using EF 5 (reverse engineered code first), my model was working fine until it suddenly stopped. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsDate' has no key defined. Define the ...
Malkin's user avatar
  • 159
7 votes
2 answers
22k views

ASP.NET MVC without Models and Entity Framework [closed]

I am going to migrate an ASP.Net application to ASP.NET MVC, and I am thinking to avoid Models and Entity Framework. Instead I will use methods to direct access databases. My question here is that is ...
Nadeem Jamali's user avatar
7 votes
3 answers
5k views

Model Warnings in ASP.NET MVC

I'm currently using the ModelStateDictionary in asp.net mvc to hold validation errors and pass then back to the user. Being able to check if the whole model is valid with ModelState.IsValid is ...
Simon Farrow's user avatar
  • 1,911
7 votes
1 answer
2k views

Can a C# named Tuple be used as an MVC page model type?

In C# 7 you can have named tuples: var foo = (Name: "Joe", Age: 42); If I pass this to a MVC model using: return View(foo); Then what syntax should be used in the cshtml file to declare the model? ...
paultechguy's user avatar
  • 2,418
7 votes
2 answers
6k views

how to change @model directive to a different model in razor view?

I have a controller that creates a model and calls a view passing the model as a parameter. In the View there is a @model directive specifying the type of Model. I want to reuse the same View, but ...
monstro's user avatar
  • 6,456
7 votes
4 answers
319 views

ASp.NET MVC - Is it possible to simplify my architecture?

I have just started working on an MVC project and things are going ok but it looks like I am creating alot of spaghetti code with just too many objects. Can anyone see how I can simplify this solution ...
Funky's user avatar
  • 13.3k
7 votes
1 answer
2k views

Why virtual keyword is used in C# master-detail model?

Refer to the EntityFramework article, and other ASP MVC webinars from Microsoft such as; 1: http://www.asp.net/mvc/videos/5-minute-introduction-to-aspnet-mvc 2: http://blogs.msdn.com/b/adonet/...
Youngjae's user avatar
  • 24.7k
7 votes
3 answers
3k views

MVC3 Not Posting entire Model

I am fairly new to MVC and am really trying to a get used to the Model Binding. I have a simple model that i have created in a form. However, when i post that form ONLY the textbox values are ...
mscard02's user avatar
  • 315
7 votes
5 answers
852 views

Hierarchical object model with property inheritance and event bubbling?

I'm writing a document-based client application and I need a DOM or WPF-like, but non-visual model that: Is a tree composed of elements Can accept an unlimited number of custom properties that get/...
Winston Fassett's user avatar
6 votes
2 answers
39k views

How to Count number of items in model using IEnumerable<T>

I was wondering is it possible to do a counter for the number of items in a model, i know using list it is possible, but id prefer to use IEnumerable for the project purpose. it would be even better ...
Matchbox2093's user avatar
6 votes
2 answers
6k views

AutoMapper, how to keep references between mapped objects?

I am using AutoMapper to convert a UI model to POCOs that I later serialize to XML using a DataContractSerializer in order to preserve the references between them. The problem comes that, when ...
SuperJMN's user avatar
  • 13.7k
6 votes
2 answers
13k views

Importing 3D model in C# -opengl

i want to know how to import 3d models from Blender into Opengl using C#.net. Blender can export model in Collada, .3ds, Stanford(.ply), .obj, .x3d and .fbx format. How to use any of the model mention ...
user1641749's user avatar
5 votes
3 answers
17k views

List model --> orderbydescending System.DateTime does not work?

Sorry if this is a duplicate but I can't find a StackOverflow post that works for me. I'm getting miffed over learning how to use list model w/ linq. My problem here is sorting by DateTime had no ...
fletchsod's user avatar
  • 3,649
5 votes
4 answers
14k views

ASP .NET MVC 3 Models + stored procedures

Im, new in ASP MVC and I don't know how to create Models which base on stored procedures from my db. I have already database which works with another application, and my web page must use mentioned db....
fgeorgiew's user avatar
  • 1,194
5 votes
2 answers
5k views

ASP.NET Core: Complex Model with comma separated values list

Our request models are growing according to the growing complexity of our APIs and we decided to use complex types instead of using simple types for the parameters of the actions. One typical type ...
EmilioV's user avatar
  • 244

1
2 3 4 5
25