MVC :: To Pass More Than One ViewModel To The View?
Sep 5, 2010
In my page there is a Login form. It looks like
[Code]....
But at the same time in this page I need to render some info from another ViewModel. Is it possible to write in action something like
return View(Model1, Model2); ?And how could I get access to these ViewModels in this case?
View 2 Replies
Similar Messages:
Mar 23, 2011
I have the following scenario;
<%
using (Html.BeginForm("actionname",
"ControllerName", new
[code]...
View 1 Replies
Mar 23, 2011
I'm trying to do a post with jQuery in an MVC application, according to this SO answer here:Can jQuery do a POST of a ViewModel to a Controller in ASP.NET MVC?The difference is I am using it to delete an item in a dynamic view (never mind the fact that I'm posting a delete directly, this is a closed site by authorization, and I will use jQuery to confirm, I just don't want the user to have to go to a new page). And I therefore need to be able to send both the id and the ViewModel (the ViewModel to save any added items before deleting any). I'm not particularly happy with the solution by and large, but at this point I just need to get it to work!So I tried to figure out how to send both the id and the ViewModel according to the SO post above, but I can't figure out how to get the ViewModel in with the named parameters. This doesn't work:
$(".delete").click(function () {
$.ajax({
type: "POST",
[code]...
View 3 Replies
Dec 21, 2010
I am creating an instance of a business layer in the constructor of my Controller and then I am passing this to my view model like this;
[Code]....
The problem is when I make a post from the view with the viewmodel, I get an error that MyViewModel doesn't have a parameterless constructor defined, and I don't want it to have. Is there anyway I can pass the _businessLayer variable from the controller to the viewmodel when it's constructed "on the fly" in a method like this;
[Code]....
Maybe by using a custom model binder?
View 15 Replies
Jun 11, 2010
when we need to pass multiple data items using a view model from a controller to a view, for example, to pass both a collection of products{id, brand, price, name} and collection of product categories{id,type} to a view, how can i validate both of these two entities?
if there is only one entity "products in the model", the validation should be somewhat like this
[Code]....
View 2 Replies
Feb 16, 2010
its said that 1 ViewModel has 1 View. 1 View is for me a UserControl. What if my UserControl has different areas filled with data from different entities, do I have then several Views and need to build several ViewModels? e.g: I display in a UserControl 3 entities: customer(listbox),order(datagrid),product(datagrid). Each of those "data areas" has add+remove buttons and textboxes to enter data.
Actually each of those "data areas" are put in its own GRID having so the posibility to set a individual datacontext.
1.) Should I now create 3 ViewModels CustomerVM,OrderVM and ProductVM?
2.) Are those 3 "data areas" seen as an own sort of separated View, although I have not put them in 3 UserControls.xaml files ???
3.) When this one UserControl is inside a TabControl`s tabpage where do I load the 3 entities related data? Inside the MainViewModel? I want to show/load that data only when the user clicks the tabheader.
View 1 Replies
Feb 23, 2011
This is probably basic stuff, but I can't find the clear answer anywhere..Lets say I'm doing an MVC (3) application with Entity Framework (EF4), and I have these three classes:
public class Foo
{
public int FooID
[code]...
View 1 Replies
Dec 13, 2010
I am trying to pass a view model of mine, which has multiple list in it, to my view. Then in my view i need to edit the different list. Then on my post i need to save the edits. Although, when i pass my viewmodel back to my post, it is empty! Can somebody explain what i am doing wrong? Controller
[Code]....
here is my View
[Code]....
NewsViewModel
[Code]....
View 2 Replies
Mar 31, 2011
I have a view model as such:
public class MyViewModel
{
public MyObject myObject{ get; set; }
public List<MyList> myList{ get; set; }
}
I have a view with a form strongly typed to MyViewModel This view allows you to enter values for the properties of MyObject, as well as create a list of MyList objects. The List part works fine although I thought that would be the more difficult of the two. Assuming MyObject has a property Description I create a textbox to enter the value as such:
@Html.EditorFor(x => x.myObject.Description);
The text box renders with an id of MyObject_Description...The problem is when I post this to my controller action, MyObject does not get bound at all(althought the list items do as they recieve the appropriate IDs of "MyViewModel_MyList[guid].myListValue")
What am I doing wrong here??
EDIT: more info
The first line of the view is:
@model MyApp.ViewModels.MyViewModel
And the Action method:
[HttpPost]
public ActionResult Create(MyViewModel myViewModel)
{
}
I am passing a new MyViewModel into the partial view to begin...
public ActionResult Create()
{
MyViewModel model = new MyViewModel();
return PartialView(model);
}
EDIT 2
Ok When I render my partial view that contains the forms I call :
@{Html.RenderAction("Create", "MyController");}
this is called from within a View of type @model IEnumerable<MyApp.Models.MyObject>
(this view displays a list of currently existing MyOjects, and at the bottom the partial is rendered to allow the user to add another MyObject to the DB)
View 4 Replies
Jan 5, 2010
I would like to know how i can bind my form values to my strongly typed view from a MultiSelect box. Obviously when the form submits the multi-select box will submit a delittemered string of my values selected...what is the best way to convert this string of values back into a list of objects to attach to my model to be updated?
public class MyViewModel {
public List<Genre> GenreList {get; set;}
public List<string> Genres { get; set; }
}
When updating my model inside the controller i am using UpdateModel like below:
Account accountToUpdate = userSession.GetCurrentUser();
UpdateModel(accountToUpdate);
However i need to somehow get the values from the string back into objects. I beleive it may have something to do with model-binders but i can't find any good clear examples of how to do this.
View 2 Replies
Apr 2, 2011
In my application, I need to get data from three tables and display them in 1 view. I have created a .dbml and created a ViewModel in my Models folder to deal with this. Here is my ViewModel:
[Code]....
My web application uses the Default ASP.NET Membership. So User [ u ] is of type aspnet_Users from the default Membership. This ViewModel allows all the CRUD opertation to be carried out. However on the Create and Update operations, I would LOVE some Model Validations, My question is:
1) Would the User [ u ] default validation kick into place in my ViewModel ? Cause I know by default ASP.NET Membership, has Model Validation.
2) For table SUserDetails (which I have created myself, not part of default) how do I add ViewModel validation to it for when someone does an Update or Create?
View 1 Replies
Jun 13, 2010
When I send a strongly typed ViewModel containing other ViewModels nested inside (basically spanning 3 tables into one object) all the data is correctly presented when debugging. However it complains at rendering time with an exception "Compiler Error Message: CS1061: 'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)"
and the error is thrown from mvc2-rtm-sourcessrcSystemWebMvcMvcViewPageControlBuilder.cs method:
ProcessGeneratedCode line 19
PageBaseType is null all the time
[Code]....
ViewModels
[Code]....
Database
3 tables make up for the ProjectModelView object
users
projects
project_bids
View 5 Replies
Jan 19, 2010
When I first heard about ASP.NET MVC, I was thinking that would mean applications with three parts: model, view, and controller.
Then I read NerdDinner and learned the ways of repositories and view-models. Next, I read this tutorial and soon became sold on the virtues of a service layer. Finally, I read the Fluent Validation documentation, and I'll be darned if I didn't end up writing a bunch of validators.
Tonight, I took a step back and thought about what had become of my project. It seems to have become the victim of the design pattern equivalent of "feature creep". Somehow I'd gone from Model-View-Controller to Model-Repository-Service-Validator-View-ViewModel-Controller. You want loosely coupled and DRY? We got your loosely coupled and DRY right here! But I'm wondering if this could be a case of too much of a good thing.
Am I right to be concerned? Or is this actually not as crazy as it sounds? On one hand, it seems crazy to have so many layers. On the other hand, every layer has a clearly defined purpose that makes sense to me. Have your MVC applications turned into MRSVVVMC apps too? If not, what do they look like? Where's that right balance?
View 2 Replies
Jan 27, 2011
Let's say there is a textbox and a dropdownlist in mainview page, these two values are used by three partial views as well. when I use Html.RenderAction to post action to those three partial views, how to pass these two values to those partial views and in those views how to get these two values as a part of a object to send to database.
View 10 Replies
Nov 22, 2010
I would like to add a partial view to my view page
The view page contain a mode name "<IEnumerable<JvTake1.Models.VortN>>
And the partial view contain a model name "<IEnumerable<JvTake1.Models.VideoL>>"
So, theoretically I think they were suppose to work together but no Can any one guide me how to make it happen?
View 2 Replies
May 5, 2010
I have a view that is not strongly typed. However I have in this view a partial view that is strongly typed.How do I do I pass the model to this strongly typed view?I tried something like
public ActionResult Test()
{
MyData = new Data();
MyData.One = 1;
return View("Test",MyData)
}
In my TestView
<% Html.RenderPartial("PartialView",Model); %>
This give me a stackoverflow exception. So I am not sure how to pass it on. Of course I don't want to make the test view strongly typed if possible as what happens if I had like 10 strongly typed partial views in that view I would need like some sort of wrapper.
View 3 Replies
Feb 3, 2011
I want to create a view that draws from mutiple sources of data and creates a 'summary' view.This would include:An author (data source A) A list of the authors latest writings (data source B) A list of topics the author writes about (data source A)I notice I cannot pass into ...return View(author, articles, topics) from the controller.It seems you have to pick one.I want to construct my View from multiple partial views for each type.Not sure I am trying to do this the correct way.
View 6 Replies
Feb 26, 2011
Suppose i have a Product and Category Model, In add new product page i want to list all categories in a listbox. For this purpose i require to have Product and Category model available to Add New Product Page View.
View 4 Replies
Apr 18, 2010
i have a view /categoria/index
[Code]....
i am trying to call the action from /imovel/index
with an id
but the thing is that i am getting null
[Code]....
View 2 Replies
Jun 23, 2010
I´have this situation: I have a Master Page for all my pages.
Inside it I have a Partial Page that render the Main Menu of my site.
My question is how to pass a data from a Controller (For example AboutController) to the Menu so it can "knows" that in the "about" li, render an aditional class in it..
Normally is: <li>About</li>
But the About page: <li class="on">About</li>
I think that controllers must send this aprameter.. or not? how?
View 2 Replies
Jan 20, 2011
I have the following action executed when a user selects an item from the dropdown;
[Code]....
The object paymentApplicationRefund is populated. I want to get the contents of this object to put in a Html.Textbox(). How do I proceed??
View 11 Replies
Sep 1, 2010
I have created a view called business this runs sucessfully ,but the problem is how will i use dynamic values in place of 12.925432,77.5940171 ,I want to pass parameter in sql query from c# code behind.
create view [dbo].[business] as
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
[Code]...
View 1 Replies
Feb 13, 2011
I want to pass a message from the controller to a view using Viewdata. Here is my code:
public ActionResult Create(FormCollection createPage)
{
try
{
......................
ViewData["Message"] = "Success - rec added!!!!" ;
return RedirectToAction("Index");
}
catch (Exception e)
{
ViewData["Message"] = "Exception: " + e.ToString();
return RedirectToAction("Index");
}
On my View I have:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>::><%: ViewData["Message"] %><::</h2>
<h3>==><%= ViewData["Message"] %><==</h3>
<p>
This is Index.aspx page in Controller folder
</p>
</asp:Content>
I am getting result with empty ViewData["Message"]
View 4 Replies
May 25, 2010
My view has a number of rows.
Each row has a drop down, a text box and an "add" link. I'd like for someone to select something in the drop down, edit something in the text box and pass that information to an Action in the Controller.
I know i can do something like this:
[Code]....
[Code]....
Which is kind of gross - id like to do just call one action, that passes the selected drop down value, the textbox value and call just the one action, is it possible to do something like this:
[Code]....
Where i pass the Dropdownlist selection and the textbox value to my controller specifically
View 3 Replies
Jan 16, 2011
In asp.net mvc3, I've got a few local variables in one of the controller, is there any neat way to pass all these variables to view? Something like "locals()" in python?
View 1 Replies