.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Is it possible to pass more than one ViewModel to the View?

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
In my page there is a Login form. It looks like <form action="" method="post"> Login: <%:Html.TextBoxFor(m=>m.Login) %><br /> Password: <%:Html.PasswordFor(m=>m.Password) %><br /> <input type=submit value="Log In" /> <%: Html.ActionLink("Forgot my password","forgot","account") %> </form> 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 Complete Post

More Related Resource Links

Design Patterns: Problems and Solutions with Model-View-ViewModel


The Model-View-ViewModel (MVVM) design pattern describes a popular approach for building Windows Presentation Foundation or Microsoft Silverlight applications. Robert McCarter shows you how the ViewModel works, and discuss some benefits and issues involved in implementing a ViewModel in your code.

Robert McCarter

MSDN Magazine July 2010

Silverlight Patterns: Model-View-ViewModel In Silverlight 2 Apps


In this article, you'll learn how to avoid problematic tight coupling by applying the Model-View-ViewModel pattern in Silverlight 2.

Shawn Wildermuth

MSDN Magazine March 2009

Patterns: WPF Apps With The Model-View-ViewModel Design Pattern


In this article we explain just how simple it can be to build a WPF application the right way using the MVVM Pattern.

Josh Smith

MSDN Magazine February 2009

How to pass page column value to data view parameters

Hi All, I have a page library with custom column, lets call it "FormCourseId". On that page I have data view which retrieves data from custom list filtered by page column "FormCourseId". In parameter wizard creates the following tag <ParameterBinding Name="ListCourseId" Location="Form(FormCourseId)" DefaultValue=""/> Then I try to use that parameter in XSLT of data view as a filter creteria.  <xsl:param name="CourseId"></xsl:param> It does not work for me. If I change data view parameter source from Form to Query String and pass parameter as url one it works fine. What is wrong with page column parameter binding? May be if FormCourseId column is not presented in form layout as a field(I do not need to show that field in user form of the page) it could not be treated as form parameter?

Another 'ViewModel closes the View' question...

Hi all, I'm somewhere in the middle of the learning curve that is the path to MVVM utopia!My question really concerns the ability to close a view from a view model.I don't want to be guilty of trying to force a solution to fit a pattern, but MVVM fits so well in all other areas there's just this one bit left to figure out.The project I'm working on is a system analagous to Microsoft Outlook.You have a main view (window) which has a list of things.These things could be messages or contacts in Outlook.From the main view you have the option to create a new thing or open an existing one.Regardless of which option you choose, a new view (window) opens to present you with a form for editing.From this point on, each new view that opens has the following options (relevant to my question)...1, Save.2, Close.3, Save & Close.Save is pretty straightforward, is just a property on the viewmodel which returns an ICommand (RelayCommand/DelegateCommand).Close is also pretty straightforward, that's just the cross in the top right hand corner of the window.Save & Close, however, is different. With option 2, the close is actually just a part of windows, we're not writing any code to do this.So how would I go about implementing option 3? Where the viewmodel first needs to persist the changes and then needs to close the view?Many thanks,MQCA

Fully Embracing the Model-View-ViewModel Pattern in WPF

I'm trying to get my head around the M-V-VM pattern as it is used with WPF. So far I have been successful in implementing this pattern but it's perfect (yet). There are a number of common UI workflows that I can't figure out how to implement in this pattern such as:1. A user clicks a button that should show a modal dialog box. Usually the VM has a command on it that the button is bound to and something executes. However, what needs to execute is a UI behavior (opening the dialog box). The VM should not open the dialog box (that would be wrong because the VM now has to know something about the UI). The Window or UserControl or Page inwhich the command was initiated should open the dialog box.2. A user clicks a button that executes a command on a VM. However, this is a long-running command and I'd like to show the WaitCursor during this operation. This is a UI function, not a VM function. Should the VM fire an event? And if so, how does the Xaml handle it?So, M-V-VM experts out there, what am I missing? Help me to see the light...Dave

(MVVM): Call Method On ViewModel From View

Hey All,   In my View, I would like to call a method on my ViewModel (all from XAML). View: <!--Parameters--> <ListView Grid.Row="2" DataContext="{Binding}" ItemsSource="{Binding}"> <ListView.View> <GridView AllowsColumnReorder="True"> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Key}"/> <GridViewColumn Header="Value"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Value, Mode=OneWay}" MinWidth="100" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> ViewModel (the Method I want to call): public ReadOnlyScriptParameterCollection GetParameters(string scriptFullTypeName) { ReadOnlyScriptParameterCollection sps = null; var scriptHost = ScriptHost.Create<JdsScriptHost>(); scriptHost.LoadFromAssembly(ScriptAssemblyPath, scriptFullTypeName); sps = scriptHost.ScriptParameters; return sps; } Is there

To Pass date in view at runtime!! Can anyone help Very Urgent

Hey I have to pass the Bussiness date in my query at run time I have tried the query below but not able to Execute it. Select * from table name where and RT.BUSINESS_DATE = ? --if only one date --if between two dates and RT.BUSINESS_DATE Between ? and ? Can Any one help me with the Syntax. Will be greatfull!!!

How to get Email of Current User Data View Web Part Sharepoint 2010 and pass to WebService data sour

I have to pass in the email address of the current user to a web service data source (run time) of a Data View Web Part.

My Question is:

a) How can I get Email address of current user based  in DVWP.
I know we can get the CurrentUser using the CurrentUserName but how do we get the Email for the Current User.

b) After getting the Email how do we pass to the Web Service.

Pass information from one web service to another web service in the same data-view-web-part


In Data View Web Part.

Is it possible to pass information from one web Service data source connection to another web service data source connection within the same Data Form Web Part to get information from second web service?

What I am trying to achieve is to get user email address from the User Profile Web Service and pass in to another web service to get information.

Please advise if it is possible.

Problem with View and ViewModel


Hi Guys!

I've a little problem with a View and its ViewModel for a basic Search Page.

I've created a View Model with 2 properties: Name (string) and NameType (Selectlist).

I've created a main strongly-typed View (Index) with these fields and I've added in the bottom of the form an Ajax.ActionLink to call the Method to search data in my DB.

The destination Method requires to fill the same View Model to catch the data inserted in the form and it launches the search engine.

Now the method returns only the data inserted in the form, but the View Model Object received is Null.

I can't find where is the problem, anyone can help me?

Here the code

Page whit form anche Ajax Action Link

<% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>
                <%: Html.LabelFor(model => model.Name) %>

Strongly typed view and viewModel


Hello together,

I have a question about strongly typed views.

I already have my business objects (based on the persistence framework xpo form dev express). These objects have some associations.

eg. an article can have some user comments


My question now is, should my strongly typed views directly base on this objects (even if these objects have many properties i never need to present)

or should i create additional classes containing only the properties of the objects which i like to present.

eg. articleViewModel and commentViewModel.

where a articleViewModel can have associations with multiple commentViewModel

The advantage which i see in the second example is, that i can easier validate the viewModels.

However it means a lot of extra work, because i need to create for all objects which i like to present a viewModel with the corresponding

associations and properties.

Thanks a lot!

Regards Vincenzo

How to Pass data(not the part of model) from View to Controller?


How Can I Pass data(not the part of model) to Controller from View?
View Code

<%= Html.ActionLink(item.Name, "ActionName", "ControllerName", new { companyID = Html.Encode("abc"), ID = Html.Encode("xyz") })%>

Controller Code

public ActionResult ActionName(string companyID , string ID)

Any idea?

pass parameters to view


on my controller i have a "delete" logic after delete i want to redirect to Index view with proper message.
How do i pass it and how i show the message on the Index view?
 // POST: /Category/Delete/5

        public ActionResult Delete(int id, FormCollection collection)
                // TODO: Add delete logic here

                var cat = db.categories.SingleOrDefault(x => x.categoryId == id);

                if (cat == null)
                    return View("NotFound");
                    ViewData["Message"] = "Category was deleted";
                    return RedirectToAction("Index");  
                ViewData["Message"] = "Error on delete Category";
                return RedirectToAction("Index");  
                //return View();

and my Index
public ActionResult Index()
            // var cat 

List view and hyperlink pass parameters Help




Anyone know how to resolve the below? I am trying to add a hyperlink to the below listview. This hyperlink passes multiple parameters to the next page? I am trying to achieve the below, works with a gridview but not below.






                        <tr >
                            <td style="text-align: center">
                                <asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" />

                             <asp:HyperLinkField DataNavigateUrlFields="searchid"

Model View ViewModel question



I´m playing around with XAML and MVVM, and have a question about the wiring between the model and the viewmodel:

If I have a model that updates its data on random times, what wiring is used between the model and the viewmodel to let the viewmodel know that the model has changed?.

Between the view and viewmodel a bindings and NotifyPropertyChanged would take care of this.


Trying to learn

MVVM Bind View Details to Model Via ViewModel when a Button clicked.


I have model called Car with prperties name,model,type,year.

I have implemeted the Viewmodel with same properties with OnpropertyChangedEvent including model object type Property.

I have a view usercontrol where textboxes for name, model and for year a combobox.

Whenever i fill the view i want to save those details into model via view model

I have written ICommand  Save which calls SaveCarDetails defined in viewmodel,  which is bind to a button in view ,All other texboxes text is bind to the properties of viewmodel properties.

When i put break point at ICommand SaveCommand and SaveCarDetails Function i could see the values filled from view.

But when i bind these details to another user control where listbox is placed and its itemsource property is set to Car property nothing but model object defined in the viewmodel.

I couldn't see the values binding via viewmodel to model.

Where as if i bind to textboxes in the listview i could see the values because i it's a dependency property.

Can any one please tell me what is the wrong i am doing here.




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend