All Questions
Tagged with asp.net-mvc-viewmodel asp.net-mvc-3
37 questions
-1
votes
1answer
114 views
MVC ViewModel - Need to define viewmodel
I am storing a questionnaire which is in xml format to a string type data field called Questionnaire. The database fields are contactID and Questionannire. I am doing this in an MVC application.Can ...
3
votes
1answer
1k views
MVC create a view model from multiple domain models distantly related
I have been searching for a way to join 2 distantly related domain models into one view model with no luck.
I am working on an existing application and have been asked to add a field to a result of ...
-1
votes
1answer
2k views
How to bind form with model data in MVC
here i have one model. now i want to buil form using html helper . so when index action will be called then i want to populate model data by hand and send the model to view.
here is my model data but ...
-2
votes
1answer
293 views
WebGrid doesn´t update when binding to a ViewModel
I´m making a site using MVC 3 and razor engine. I have a WebGrid that has a ViewModel as it´s source that it´s not updating. Weird thing is that it only updates when I recompile the project, and I ...
1
vote
0answers
370 views
DropDown list issue in knockout js asp.net mvc 3
I have the following problem. I'm developing web application on asp.net mvc and using KnockoutJS in one of views. I have the following viewmodel
public class ExampleViewModel
{
public ...
0
votes
2answers
885 views
Object reference not set to an instance of an object in view model
I get this error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for ...
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 ...
4
votes
3answers
1k views
Decoration on ViewModel property to use a different name for binding
On MVC3, is there a way to decorate a ViewModel property in order to get the DefaultModelBinder to use a different name for it in the request?
For example, suppose you have the following view model:
...
0
votes
1answer
191 views
MVC3—Trouble binding complex model
I need to update a company class with an IList of addresses. These are my Data Models.
// Entity class Company — managed by Nhibernate
public class Company
{
public virtual IList<Address> ...
1
vote
4answers
328 views
MVC viewmodel redundancy
Wouldn't creating ViewModels lead to redundancy? In the sense I have my domain model and I need to display the data from it on a view. So we create ViewModels, add DataAnnotations to it and display it ...
15
votes
3answers
29k views
ASP.NET MVC View Model not binding on HTTP Post with DropDownList
I am having an issue that when I post to a controller I lose binding and everything in my view model is NULL. Here is the code I am using:
View:
@model ArticleCategoryVm
@using (@Html.BeginForm())
...
1
vote
3answers
2k views
Get route {id} value in view?
I known if I have something like /controller/action/{id} I can access id as a function parameter. But how would I access it via the view without using the viewbag?
4
votes
2answers
9k views
Show multiple models in a single view using ViewModel in Razor MVC3 (with only Details in view)
My task is to show multiple models into a single view.I've created a ViewModel for my requirement but I'm not meeting my requirement.
please have a look into the below code and rectify me where m i ...
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 ...
0
votes
1answer
255 views
ASP.NET MVC 3 - Content loaded into ViewModel is lost after callback
I make a callback jQuery function to fill some collections into my ViewModel with values. When I call this function again, the ViewModel loses the content populated in the first callback.
// ---------...
0
votes
2answers
70 views
How do I populate HTML content with new values once data has been changed on postback?
I have MVC3 razor application. Once I'm submitting a form and in Action i'm changing ViewModel content, i can't see new values populated.
There was a topic about that in MVC2 where guys told that it ...
2
votes
0answers
2k views
ASP.Net MVC File uploading ViewModel Binding
So I'm fairly new to ASP.net MVC and have been trying to make a fileuploader, but I can't seem to get my uploaded file bound to my viewmodel. I'm trying to apply validation to the uploaded file ...
2
votes
1answer
3k views
Why is my http post returning null from my view model
This is my model:
public class Attribute
{
public string Key { get; set; }
public string Value{ get; set; }
}
I fill it in my GET create
public ActionResult Create()
{
var ...
0
votes
2answers
84 views
How can you do multiple saves of a model in one submit?
I have a model:
public class CustomerAttributes
{
public Int Id { get; set; }
public string value { get; set; }
}
my create view looks like this:
<div class="editor-label">
...
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.
...
2
votes
2answers
930 views
ASP.NET MVC View-Model: reload from backend on invalid post or put all properties in hidden inputs
I'm using ASP.NET MVC3, and I've got a view-model with several properties, some of which are for display to the user, and some of which are used as inputs from the user and may have default values. I'...
0
votes
2answers
223 views
Passing values to view in Asp.net MVC3
I have two tables Date and Song. Where DateId is foreign key to Song table.
- Date:
DateId
Date
- Song:
SongId
DateId
Title
Here is the function:
public ActionResult Index()
...
0
votes
2answers
744 views
validate the individual property of viewmodel using data annotation
I am trying to built multiple file upload using view model and data annotation. Following is view model:
public class UploadNewsModel
{
[File(AllowedFileExtensions = new string[] { ".jpg", ".gif", "....
2
votes
1answer
5k views
ViewModel for multiple file upload in ASP.NET MVC 3
I have multiple file upload Views with ViewModel binding as following:
@model IVRControlPanel.Models.UploadNewsModel
@using (Html.BeginForm("index", "NewsUpload", FormMethod.Post, new { name = "...
4
votes
1answer
7k views
MVC3 Custom Validation error message doesn't display when using ViewModel
SUMMARY
Question: Why doesn't the custom validation error message show when using a ViewModel.
Answer: The custom validation should be applied to the ViewModel not the Class. See the end of @...
0
votes
1answer
265 views
Can't populate ViewModel
MVC3 project.
I have several classes: Account, Address, Phone etc. which I set up in a view model
namespace ViewModels
{
public class AccountVM
{
public Account Account { get; set; }
...
0
votes
2answers
166 views
MVC c# ViewModel with table object
I have a viewmodel as such
public class NoteViewModel
{
public tblNotes tblnote { get; set; }
}
In my controller, I do the following next after doing a build so my controller ...
2
votes
6answers
3k views
ASP.NET MVC3 ViewModel - Confused
I'm learning about ViewModels in C# ASP.NET MVC 3, and I'm stuck at displaying data from the ViewModel in my View.
The Models:
public class Author
{
public int Id { get; set; }
public ...
1
vote
1answer
2k views
How do I bind multiple dropdownlists
I am dynamically loading a partial class with dropdownlists. The dropdownlists represent the many side of a one to many relationship. One person registering with multiple apartments. See pic below. ...
2
votes
3answers
13k views
How do I sort a list of entities using ViewModel instead of ViewBag?
I am using ViewBag to help me sort a list of students found within a list of classes. I have read that ViewBag is something that should be avoided at all costs attempting to build a proper MVC ...
7
votes
3answers
1k views
ViewModel Implementation in ASP.NET MVC - Is this code best practice?
I've just started to get into using ViewModels. Can you guys check out this code to see if I'm following best practice? Is there anything out of the ordinary? Would you do the validation differently?
...
1
vote
1answer
1k views
How can I make ViewContext available in my viewModel?
In my controller I have the following code:
var viewModel = new ListCityViewModel {
City = rowData,
Meta =
{
DataSourceID = ...
0
votes
2answers
155 views
Can I simplify this C# in my ViewModel?
In my code I have the following:
viewModel.Note.Modified = DateTime.Now;
viewModel.Note.ModifiedBy = User.Identity.Name;
and in my view:
[DisplayName("Modified")]
public DateTime ...
5
votes
1answer
24k views
Using PagedList with a viewmodel MVC 3
I am trying to implement IPagedList with a viewmodel, my main view declaration is
@model PagedList.PagedList<CustomerOrders.WebUI.Models.SiteAdminListViewModel>
Then i have a Display Template ...
3
votes
1answer
805 views
custom model binder with complex type MVC 3
I have the following ViewModel and i would like to create a custom binder to bind subclasses (LogOnModel, ChangePasswordModel).
public class LogOnViewModel
{
public string NextStep { get; set; }
...
32
votes
3answers
90k views
The model item is of type CookMeIndexViewModel, but requires a model item of type IEnumerable<CookMeIndexViewModel>
I am following along with the music store example to try learn ASP.NET MVC. I'm creating a cookbook application.
I have created my viewmodel that looks like this:
namespace CookMe_MVC.ViewModels
{
...