All Questions

2
votes
1answer
22 views

Partial View with variable model type

Update from Travis Answer : public interface IEntity { int Id{get;set;} string Name{get;set;} } public class Vehicule:IEntity { public int Id{get;set;} public string Name{ get; set; } ...
0
votes
0answers
37 views

Html helper to render UI elements from javascript

I am populating a table with education records from a section of an html page. I am using hidden inputs so as to be able to submit the data from my viewmodel. Because I cannot find a way to use Html ...
0
votes
3answers
59 views

Is it possible to combine 2 view models, each populated with 2 different LINQ queries and return to 1 view?

I am trying to display 2 sets of data in 1 view: First LINQ: var result = from add in db.Addresses join u in db.Users on add.UserID equals u.Id where ...
0
votes
0answers
10 views

IPagedList Paging feature with reading related data using viewModel does not work

I am in a process of creating a web app to display a set of reports and when clicked on a particular report it should display The properties of that report below. I'm using two models i.e Report and ...
0
votes
0answers
80 views

Using ViewModel with multiple Models in ASP.NET MVC

I use the following approach when creating a ViewModel with multiple models (entities) in ASP.NET MVC: Student Entity: public class Student { [Key] public int Id { get; set; } public ...
0
votes
1answer
85 views

DataType.PhoneNumber Attribute has No Effect on Display

I have a [DataType(DataType.PhoneNumber)] on a String field in my view model. When the phone number is displayed, however, it is rendered as a simple string with no formatting. Another field in my ...
1
vote
1answer
34 views

How to use ViewModels with Partial Views

I have read a lot on viewmodels including various posts on SO and I am still not sure how to fully implement them. I am creating an auction site and I have my Home index page. What I want to do is ...
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; ...
1
vote
1answer
48 views

Partial viewmodel is null when posting to controller

I've got a viewmodel that contains other viewmodels. public class AggregateVM { public BrandVM BrandVM { get; set; } public TinTypeVM TinTypeVM { get; set; } } When I http post to the ...
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
2answers
73 views

Get current action in mvc view model

I have a view model that is shared between several actions. Is it possible to get the name of the action that is being called and, if so, how do I achieve that. I need the name of the action inside a ...
0
votes
0answers
53 views

ASP.NET MVC ViewModels to combine many-to-many model relationship to View

I am building the classic movie catalog project. I have a many-to-many with movies and genres so that I can list the genres in movies and vice-versa, etc. I am having trouble doing that with my ...
0
votes
1answer
30 views

building view using a generic interface

I am working on an ASP.Net MVC Website. I have a table called animal, which is created based of this class using Entity Framework code first: public class Animal { public int AnimalId { get; set;...
0
votes
2answers
220 views

Session Variable Lost after return Redirect function

I have an mvvm web app that is used for sorting values The user clicks on sort and the following code within the element sends it to controller as a parameter, refreshing the page. <a href="@Url....
0
votes
0answers
15 views

use of two models in mvc view [duplicate]

Good day, I have a layout with a search box(with bootstrap and a self-made jquery typeahead). <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> ...
0
votes
0answers
51 views

ASP.NET MVC - many-to-many relationship show data in viewmodel [duplicate]

I have Two Model Product and Category should to have many-to-many relationship between them, I want to show my categories in List Box to customer select multiple categories, but it's not show any ...
0
votes
0answers
29 views

Pass one of many objects from view to controller

In an ASP.Net Core web app, I'm passing a List<Parameter> to a view via ViewBag.Parameters. The view also has a SelectParameterViewModel that consists of one property only, an int ParameterId. ...
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 '...
-1
votes
1answer
74 views

Best approach ViewModel or ViewBag and DataAnnotations or Jquery Validations

I know this is kind of old question, however, I didn't see a proper answer anywhere else. ** code ** public class ViewModel { public string AdType { get; set; } public Ad ...
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 ...
0
votes
0answers
31 views

How to achieve showing summary products in view using Asp.Net Mvc

I have three kind of products showing on my index view divided in 3 slots like this <div class="panel panel-body"> <div class="col-md-4 table-responsive" id="carTable"></div> ...
0
votes
1answer
58 views

How to access attributes of ViewModel inside Views

I have below ViewModel: public class RegisterViewModel { [Display(Name = "First Name")] public string FirstName { get; set; } } In my view, I'm using DevExtreme components and syntaxes. ...
0
votes
2answers
73 views

How do I update a specific database entry with a view model as controller method attribute

I have an input table in my website which is connected to a View Model. In the controller method, I pass this View Model to the controller and vice versa, meaning the controller populates the view ...
0
votes
1answer
46 views

How can I make view cshtml for my Edit ViewModel

This is my ViewModel namespace CRUD2.ViewModel { public class CostVM { public int id { get; set;} public string nama { get; set; } public string alamat { get; set; } ...
0
votes
1answer
326 views

Passing same Model/ViewModel to multiple Partial Views (tabs in jquery)

A bit new to .Net + MVC dev. background... in my lil app i have 3 tables ... applications, databases, and app_db_support table. The 3rd table has fks to the first 2 and stores associations. Want to....
0
votes
1answer
129 views

Viewmodel property could not be found

When submitting my form I'm getting an error that says some property 'Password' I don't have in my viewmodel could not be found. System.ArgumentException: The property ProjectName.ViewModels.User....
1
vote
3answers
48 views

Trying to create view with 2 models gives error

So what im trying to do is make a view with 2 of my models. For that i made this viewmodel: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ...
0
votes
1answer
79 views

ASP.NET MVC View doesn't return the Child Objects of One-To-Many Relationship to the Controller Action

I have two classes with one-to-many relationship. public class Article { [Key] public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual int SortOrder { get;...
1
vote
1answer
400 views

ViewModels in Repository

I have read that the repository layer should not deal with ViewModels because of separation of concerns and should instead deal only with Models. This is also true for the service layer (in my case ...
0
votes
2answers
128 views

SelectListItem properties in view model are not passed back from view to controller

I have this View Model: public class UserViewModel { public string ID { get; set; } [Required] [Display(Name = "Nombre")] public string Nombre { get; set; } [Required] [...
0
votes
0answers
159 views

Creating a ViewModel with foreign keys

I'm just a beginner in MVC, so please help me out and bear with my question. I have a scenario, but I can't figure it out how to create a proper ViewModel for this. I have a ProjectViewModel which ...
1
vote
4answers
141 views

asp.net mvc - nearly identical ViewModels [duplicate]

I am building a web application with ASP.NET MVC and am still a beginner with this technology. I have learned that it is best practice to have a ViewModel for each View. I can understand why this is ...
-1
votes
1answer
87 views

Update Viewmodel's property with TextAreaFor returns null values on POST (ASP.NET MVC 5)

I am developing an application for managing student files through school years. It involves listing students in classes, displaying a profile per student and editing information such as an ActionPlan. ...
0
votes
2answers
649 views

Loading LINQ results into a ViewModel that has a calculated attribute (column)

I've seen the scenarios where a ViewModel is populated with one LINQ query as shown below. Question: How can I populate the TotalSale attribute (column) - that is a grand total of Sale column - of the ...
0
votes
0answers
57 views

Automapper gives null after mapping

var objInterview = ServiceManager.InterviewServiceInstance.GetInterview(InterviewID); Mapper.Initialize(cfg => { cfg.CreateMap<Interview, InterviewViewModel>() ...
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 ...
0
votes
0answers
387 views

When click on button in ajax to pass values to controller and displays back to same view page, page loads only array of loaded data

The table rows are generated at page load using ajax as shown below. $.ajax({ url: '/consultation/GetPrescHistoryList', type: 'POST', data: $('#frmPrescHistoryTable')....
0
votes
0answers
215 views

asp.net mvc viewmodel null reference exception

I work on a asp.net mvc project. I start to get "object reference" error message. My Action method returns viewmodel. return View(GetDetail(Id)); When I debug and watch returned model I see that ...
0
votes
0answers
68 views

ASP.NET MVC Data Annotations Persisting Between Layers

I am learning MVC, and in trying to separate my business layer I cannot get Data Annotations to persist between them. For Instance I would like the Name of a Column to persist throughout my ...
0
votes
0answers
26 views

MVC - how to change existing view to strongly typed view [duplicate]

In my MVC EntityFramework Application, I want to pass multiple data sets to the view and for that I need to convert the existing view to a strongly typed view. So I have added this line at the top of ...
0
votes
1answer
84 views

Model list becomes null when passing the view model to another method

I am using ASP.NET MVC5 my ExternalLoginConfirmationViewModel contains these: public List<Education> edus { get; set; } public List<Experience> workplaces { get; set; } in my ...
-1
votes
1answer
93 views

How to utilize C# properties correctly in this specific ASP.NET MVC scenario?

I have properties defined in my view model like so - public string FullName { get { return FirstName + " " + LastName; } set { FirstName = ...
0
votes
1answer
46 views

Design pattern: how to pass parent object ID to form for HttpPost processing

I have to following class hierarchy: public class Parent { public int ID {get;set;} public string SomeOtherProperty {get;set;} ... public virtual ICollection<Child> Children {...
2
votes
2answers
118 views

How to configure a ViewModel and Partial Page to include an IEnumerable

I'm trying to change my ASP.NET MVC project from straight Views and Models to using a ViewModel intermediate layer. Basically, what I'm doing includes having a Person with zero or more Events ...
2
votes
1answer
104 views

Should I store view models or domain models in session?

Am a little confused about session state storage. I have an MVC application, there are view models, which are closer to the view, then there are the domain models which have rich behavior. We are ...
0
votes
0answers
68 views

How to sort a Grid using Viewmodel not ViewBag?

I have my code working and sorting correctly but I am using ViewBag to do so. I would like to clean up my code and use ViewModel instead to sort my grid but I'm stumped in how to do so. Any help would ...
1
vote
3answers
76 views

ViewModel or View responsibility in draw logic

Yesterday I had a little discussion with one of my work partners about ViewModel and View responsibility. I have a text that changes in different contexts, like Edit/New mode in the View. One of the ...
0
votes
3answers
109 views

is there a way on adding two models properties inside ASP.NET View

I have been trying to make this happen for a few hours now.I have two models within my model folder called Models, i am trying to pull data from the model to display it in the view, i am aware of only ...
0
votes
0answers
69 views

Fetch all related data into view on get & filter data on post request

Ok I have an ASP.NET MVC application in which I have following three models public class Student { public int Id { get; set; } [Display(Name = "First Name")] public ...
0
votes
1answer
66 views

Each validation summary linked to it's own partial view

I have a view that is composed from 2 partial view plus what is already in the page. I want each view to have a validation summary. Everything is working fine except that when there's an error in one ...