All Questions
Tagged with asp.net-mvc-viewmodel viewmodel
49 questions
0
votes
2answers
108 views
how i update multiple table using viewmodel in Asp.net mvc
Employee Model
public class Employee
{
[Key]
public int EmployeeID { get; set; }
public string Name { get; set; }
public virtual Department Departments { get; set; ...
3
votes
3answers
208 views
Can we use only DTO instead of ViewModel? [closed]
We currently use DTO for Web API request and response
and use ViewModel to pass data to the View in MVC
Currently, we have:
DTO as a separate project
ViewModel is inside the UI project (another ...
0
votes
0answers
11 views
View POST property of object with null instance
Why is the View returning a null reference to an object that is explicitly set in the ViewModel?
NullReferenceException: Object reference not set to an instance of an object.
xxx.Controllers....
0
votes
1answer
72 views
Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime' when inserting into Database using EFW and ViewModel [duplicate]
I am working on this ASP.NET Core MVC project where I am trying to save the values from form into Database when I am getting this error:
Cannot implicitly convert type 'System.DateTime?' to '...
0
votes
1answer
226 views
passing viewmodel and a multiple file upload's content of files to the controller
I'm trying to pass a viewmodel and a multiple files uplaoded using a file upload control to the controller. No matter what the files argument is passed as null.
How can the uploaded files be passed ...
-1
votes
1answer
187 views
LINQ in .NET MVC: Any advantage to creating a ViewModel vs. joining tables?
I'm working on a simple project where I have data in two tables that I need to return to my View from my controller. I'm aware of two methods to do this in .NET, the first is create a model class, add ...
0
votes
1answer
35 views
Null reference issue occurs when converting from Domain model to View model
The below code throws null reference exception when there is no data to be returned from the stored procedure. Method executes successfully if data is present.
Am I doing anything wrong with the ...
0
votes
1answer
62 views
Simple getter logic in ViewModels
Is it ok to have simple logic (without any dependencies) in ViewModels getters or it should contain just automatic properties? in this case just checking for null so I don't have to do that in ...
1
vote
2answers
55 views
ViewModel returns same values for all 500+ records to the view
I am new to using ViewModels, I have a new list here and am adding items to it by looping though a database table. The issue is that all the records that come back are identical using the same record ...
1
vote
2answers
1k views
Separate ViewModel for Read, Create, and Update actions in ASP.NET MVC
I use the same ViewModel in ASP.NET MVC projects, but for a thousand of records it seems to be better not to retrieve unused records from database. For example, assume UserViewModel for Read, Create ...
-1
votes
2answers
289 views
PartialView with a ViewModel on _Layout.cshtml
I have a layout page which has a partial view. The partial view needs to loop through a property on the view model to show a list of categories. When a category is displayed I need to show a list of ...
0
votes
0answers
65 views
MVC ViewModel State Dropdown
I am new to MVC and View Models, and trying to wrap my thoughts on how it all works and ties together. I am trying to populate a State dropdown in an Address table. I have a States table with ...
0
votes
1answer
136 views
How to access data from differnt partial view after POST
I have 3 partialviews with 3 viewmodels on page:
List of accounts
Modal popup (you can modify multiple accounts here)
Search panel
I want to refresh 1. after doing POST on 2. This is ...
0
votes
1answer
45 views
Models in viewmodel gave me null error while they are'nt null
I'm developing a Asp.net MVC 5 webApplication with Razor Engine. I have a layout that shows some data from this models: (Footers , FooterMenus , SocialNetworks) from db , and I have a view named ...
0
votes
2answers
510 views
How to get list of ViewModel from database?
I have a view model class for getting a list of Clients with their list of offers.
Restaurant Viewmodel
public class RestaurantsListVM
{
public Client client { get; set; }
public List<...
0
votes
0answers
64 views
To reduce code duplication in controller
This is my simple controller which is dependent on EventsViewModel. After fetching required fields, i am comparing the data returned and fill it into two variable and finally returning back ...
2
votes
0answers
2k views
MVC 6 - ViewModel Builder Concept
I started refactoring an ASP.Net 5 web application which uses MVC 6 and Entity Framework 7 when I was wondering about some points. My controllers currently use the DbContext implementation via ...
4
votes
2answers
7k views
asp mvc list product details in view using View Model
I am trying to list single product details in a view. The product specification changes dynamically because specifications are added row-wise in table, which means we can add huge number of ...
-1
votes
1answer
636 views
Asp.Net MVC 5 1 View 2 models with viewmodel The model item passed into the dictionary is of type error
I am new to Asp.Net MVC and I am coding a simple blog with using ASP.NET MVC 5 Framework. I can create edit and delete posts. You can see my code on GitHub in details. And I want to add comment ...
-1
votes
2answers
406 views
How to send data from nested ViewModel to Controller
I am using nested view models to display views based on user roles.
Model:
public class MainVM {
//some properties
public OneVM One {get; set;}
public TwoVM Two {get; set;}
}
public class ...
1
vote
1answer
479 views
How use viewModels + Entity Framework? Is necessary add a migration?
I am using asp.net mvc 4 + entity framework and for the first time I'm using ViewModels. I'm reading this tutorial: http://www.asp.net/mvc/overview/older-versions/mvc-music-store/mvc-music-store-part-...
3
votes
2answers
2k views
Iterating ICollection from ViewModel within View
I have two autogenerated database models (Product and ProductDetails) which I merged into a ViewModel so I can edit all data at once.
What confuses me is the part where I am supposed to iterate ...
2
votes
1answer
715 views
Constructor or Property Injection for View Models?
I recently posted a question about Ninject not injecting expected IList<T> upon a repository method call which returns an IList<T> into a view model constructor which given answer is to ...
0
votes
1answer
48 views
Show Files trough viewmodel isn't possible because of static types cannot be used as type arguments
I've done a file upload in my wabaplication and I'm making the view that retrieve thos epictures and show them to the user. I use ViewModel show data to user and I get error when i try to add List<...
0
votes
2answers
157 views
Switching MVC view on Post back using strongly typed views/view models
User requests page for Step1, fills out and submits form that contains selected person, so far so good. After validation of ModelState the next viewmodel is constructed properly using the selected ...
1
vote
2answers
905 views
C# MVC saving only the changed elements of a view model with Entity Framework
I have a project where multiple users may look at the same page of data at the same time, and make changes to it. Because of this, the lost update problem will occur.
I want to know if there are any ...
3
votes
1answer
1k views
ASP.NET MVC 1 ViewModel per View?
I've read article "How we do MVC". In rule #3, said that "we only have one ViewModel type per View". For example, when we scaffolding in mvc, it's automatically create 5 Views (Create, Delete, Details,...
0
votes
1answer
98 views
Am I misusing or misunderstanding viewmodels in MVC?
I'm using ViewModels in MVC. I'm find them incredibly klutzy and wonder if I'm doing something wrong. (Let's leave Automapper out of this for the sake of discussion.) I use viewmodels to send data to ...
8
votes
2answers
23k views
How to use ViewModels in ASP.NET MVC?
I just started learning about ViewModels in ASP.NET MVC. So, I thought of implementing a sample example as below:
Business Entity
public class AddModel
{
public int a { get; set; }
public ...
1
vote
2answers
37 views
What is the performance optimum (or even better coding practise) for writing this Linq query
I am new to linq so please excuse me if I am asking a very basic question:
paymentReceiptViewModel.EntityName = payment.CommitmentPayments.First().Commitment.Entity.GetEntityName();
...
0
votes
2answers
136 views
Asp.Net MVC Adding two viewmodels to a third
I have two viewmodels, VM1 and VM2 - I want to add these to a third viewmodel, so I can send two tables of information, to my view - but I'm struggling.
My viewmodels are:
public class VM1
{
...
0
votes
1answer
26 views
ViewModel Redundancy Clarification
I was recently reading about ViewModel and its advantages. I am able to understand why it is needed, however the question I have is If i have two classes for the same object(ie. Person class), doesn't ...
0
votes
1answer
160 views
Can a 'ViewModel' hold 'DomainModel' type property
In asp.net MVC 4, I have 2 DomainModels
Product
Order
and a related ViewModel
OrderDetailsViewModel
In my "OrderDetailsViewModelMapper" mapper file I am manually mapping these 2 ...
3
votes
2answers
22k views
MVC ASP.NET No parameterless constructor defined for this object
When I click submit in order to create an account the following error is displayed. I can't find why it is giving the following error. Also I tried to use breakpoints and debugging but it was useless
...
0
votes
0answers
256 views
How do you bind a nested viewmodel list with a custom modelbinder?
I'm trying to bind a viewmodel with a dynamic list of nested viewmodels. I figured out on how to bind 1 viewmodel that is nested. But how do I bind a list of them?
My classes:
public class ...
0
votes
1answer
212 views
Reuse DisplayAttributes with view model properties
Is there a way to use the DisplayAttribute values of an entity within a view model?
public partial class Catalog
{
[Display(ResourceType = typeof(Resources), Name = "ID")]
public string ID { get; ...
0
votes
2answers
885 views
How do I only update properties on the original (DB) object that have been changed in the view model?
For example, I have a DateCreated property on my Product and ProductDetailModel classes. Yet, on my Edit view, I have no DateCreated input, or any kind of storage. When I edit a product with a ...
1
vote
1answer
3k views
Knockout view model posts back to ASP.NET MVC partially - how to post back complete object?
Having these ASP.NET MVC view models:
public class User
{
public string Name { get; set; }
public LabeledEmail LabeledEmail { get; set; }
}
public class LabeledEmail
{
public IList&...
0
votes
1answer
921 views
ASP.NET with Knockout variable length list with combobox - how to bind?
With the following ASP.NET models
public class User
{
public string Name { get; set; }
public LEmail LEmail { get; set; }
}
public class LEmail
{
public IList<CLabel> Labels;
...
0
votes
1answer
264 views
MVC razor layout - modify from view
This is my layout page:
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8'>
<title>@ViewBag.Title</title>
</head>
<body>
@...
6
votes
2answers
2k views
ASP.NET MVC with nested view model and Knockout
Cannot get my brain around how to implement knockout for the following ASP.NET MVC 4 nested view model :
public class MyProfile
{
public string Name { get; set; }
public IList<VM1> List1 ...
0
votes
1answer
1k views
Multiple models in view error
I have a view pages that have different partial views with different models. I created a model class that will call other classes so i can use it on the main view page. But my problem is that when i ...
1
vote
2answers
182 views
Passing multiple view models in a single view
Even though that i believe that i have all the models defined and hopefully passed in properly but i am getting an error which states that i am passing in one model when it requires another model.
...
1
vote
1answer
462 views
Razor view page with multiple partial view razor pages
I am somewhat new to this and I am having trouble displaying a page which contains partial views and I want someone to look over my structure and maybe point out what I am doing wrong.
This is my ...
0
votes
1answer
779 views
ASP.NET MVC 3 + Serializing a collection displayed into <table>
My ViewModel contains a collection of some object (IEnumerable). The items of the collection are displayed on rows into a tag. When I submit my form, it's triggering submit jQuery function to ...
3
votes
1answer
3k views
ASP.NET MVC ViewModel Good Practices
First i want to share with you this very interesting article about ViewModel :
http://rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp.net-mvc-applications
I have one questions
...
1
vote
1answer
605 views
MVC 3 viewmodel properties
I have a question regarding organization of properties in viewModel. As far as I understand the viewmodel should be as simple as possible, and the main thing that it should do is bind data to view.
...
1
vote
1answer
438 views
How to code a viewModel with nested classes
My web page / view will have 1 to many import records.
Within each import record will be 0 to many of the following:
Purchase Orders
Shipping Containers
Products
Invoices
I have coded my view model ...
0
votes
3answers
661 views
MVC2 controller not receiving all data from view on submit
I have an app that calls a web service to display import records based upon criteria entered by the user.
Each "import" can have 0 to many PurchaseOrder, 0 to many Containers, 0 to many Products, 0 ...