MVC :: Bind Two Different Models To Single View?

Oct 13, 2010

I have one view page.now what i want to do,i want to bind two models to same view.

I have to bind two different models to single view.

I have bind view with storngly type with Department model First display all the Department, now on click of Department i have to show the Courses associated with that Department.

How can I achieve this.

View 18 Replies


Similar Messages:

Multiple Models Sent To A Single View Instance

Jan 5, 2010

I'm trying to learn the ropes of ASP.NET MVC and so far so good. One thing which I haven't seen addressed yet is the 'right' or most elegant way to pass multiple data models to a view. To help put the question in context, take this example: Say I was making a blog. When I log in I want the home screen to display a list of all new unapproved comments, as well as a list of recently registered users, and a list of the most recently submitted blog posts.

Most discussions I've seen suggest strongly-typing the view page so it can be called with something like "return View(RecentComments)" and iterate through the comments in the view, or to cast the data model like "var NewUsers = (MembershipUserCollection) ViewData.Model". What I'm ideally after is the 'right', or at least a 'right-enough', way of passing multiple models while still maintaining appropriate logic separation.

View 6 Replies

MVC :: Best Practice To Have Multiple Strongly Type Models Inside A Single View?

Oct 26, 2010

So far I've seen demos of MVC that have simple pages, one for login, one for register, one for listing a table. In order to understand better the transition for WebForms developers into MVC patterns, I would like to understand how can I put together multiple CONTROLS (like the one provided by the default MVC project that VS2010 creates for us ...and make it work. OK so as an example, imagine we want to change the LogonUserControl.ascx to allow us to login (so to show UserName and Password textboxes and Logon button) from the Home Page.

1) We update the Control as follow:

2) We update the HomeController.cs file to handle the Logon Button Post event as follow:

We needed to move some code from AccountController to HomeController in order to get the control to work under the Index view. So ...with little luck it seems to work! Now the problem happens when you navigate to the Register view, considering that now we are not any longer on the HomeController "domain" but we are under AccountController. Register page shows perfectly and since the LogOnUserControl.ascx belongs to the MasterPage, it shows too. Since we are not logged yet, it will be displaying the UserName and Password textboxes. But we don't really care about that, because we are on the Register view and after populating the Register values, we click on the Register button. This is the error I get:

>>> To me that I come from the WebForms world, it seems like even if the event fired was the Register button (therefore under the AccountController domain), there is a kind of hidden OnInit event fired for any control on that view, in this case the Logon event. I'm sure this is NOT the case but the real question is... if we are allowed to have only one Controller x view, how can we put together controls that come from different "controller domains" and display them inside a single view?

Could I develop an eCommerce site using MVC that has the home page displaying different controls like [Most Purchased Product, Product of the Month, Special Promotions, Messages Inbox, Company Events ... and each control has it's own button to click and do something (so a proper POST request)] on the home page, unless I only have ONE single Controller which i'm not even sure if it will work or if it would make sense ....since MVC is all about separation of responsibilities.

View 7 Replies

MVC :: Making Base Models With View Models

Nov 3, 2010

i have a base controller that looks like this:

[Code]....

and a contact model that inherits from the base model.

the master page inherits form the base model,

nad the contact page inherits from the contact nodel,

but then i get an error while loading the contact page that it expects the contact model but gets the base model?

View 9 Replies

Forms Data Controls :: How To Bind Detail View To A Single Record Custom Class

Jun 17, 2010

so how to bind detail view to a single record custom class?

[Code]....

Apparently I can do it this way.

[Code]....

But I don't think my way is a proper way..

View 3 Replies

How To Bind Post Data With A Model That Contains Multiple Models

Nov 4, 2010

I have a parent View that uses a few partial views. Each partial view has its own custom model. The parent View is a model containing each of the partial view's model. In other words this parent View model is NOT flat.

How do i get POST data to bind with the parent's model object? Do i have to write a custom model binder?

Update I'm not binding to a collection of objects of the same type (ie: a collection of uploaded files). I'm binding to object that contains multiple of objects. For example:

[code]....

View 1 Replies

C# - Can Send Different View Models To A View?

Feb 4, 2011

I am implementing a view for Food. (ASP.NET MVC2) Then depending on the type (say fruit or vegetable for example) I will change the view.

Can I do this without creating a seperate view for fruit and vegetable?

I.e. Say we have url structure like [URL] and don't want [URL] [URL]

So I want to be able to change the view depending on the type. I'm using a tabstrip control from telerik, to give you an of the difference in the views - it'd just be say - not displaying one particular tab for Veg, and displaying it if fruit, for example.

Can a view accept two different view models ? so when we hit [URL] the code determines what type the object is (Fruit or Vegetable) then sends either FruitViewModel or VegetableViewModel ? If I just send one viewmodel how can I control the logic to display or not display certain things in the view?

View 3 Replies

MVC :: How To Have Multiple Models Per View

Apr 14, 2010

<%@ Page
Title=""
Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<JCIOrange.Models.UserProfile>" %>

How do I display more than one model per view? The above line limits me to only display UserProfiles. I want to also display other models, like UserJob and etc....how would I go about doing so?

View 1 Replies

Use RenderPartial Twice In View With Different Models Associated?

Mar 18, 2010

I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no prefix, so even the id's or names are equal in the output. Now, if I have model errors for nickname or password, both fields get highlighted.

Main View:

[code]...

How can I change this?

View 4 Replies

MVC :: Two Models Passed To A One View?

Sep 6, 2010

I'm trying to develop my application and I've got a master page where I'm planning to create a div container, where my "news" will be loaded from my database and will be shown always on a main site. Then inside of the main placeholder I'm planning to load some extra data too from my database... and there's the question: how to solve that ? is there any possibility to pass a model to a master page ? or two viemodels to a view page inside the main placeholder on my page ? (one with news, and other containing some other data).

View 4 Replies

MVC :: Validating Multiple Models In The Same View?

Jul 4, 2010

I am having two models User and Address. In the create User view apart from the user information, the user can add one or more addresses to himself. So is there a way to do model based validation for multiple models in the same time ?

View 9 Replies

MVC :: ViewMaster And View Contains Two Efferent Models?

Jan 5, 2011

I have a requirement where i need to use Master Class (a class in my model) as ViewMaster's Model and the View using MasterDetail (another model). i use them in this form and View in this form

<%
@
Master
Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage<HotWorldPOS.Models.MasterNavigationModel>"
MasterPageFile="~/Views/Shared/Site.Master"
%>

[Code]....

I get an exception when i run this

The model item passed into the dictionary is of type 'Models.GeneralMasterModel', but this dictionary requires a model item of type 'Models.MasterNavigationModel'.

my requirement is like this, the viewmaster is of three column layout, first column showing an IEnumerable containing some navigation links, the third column contains an IEnumerable of MasterDetail class depending on the Master object clicked, and the center column is the content place holder for displaying child views (for editing, displaying selected masterdetail). this view's model will be deferent for each masterdetail selected.

View 2 Replies

MVC :: Handle Multiple Models In A View?

Aug 11, 2010

How do you handle multiple models in a view?. I have 2 tables. Member and MemberAddress

Member class contains Collection of MemberAddresses since a single member may have a billing and shipping address:

public class Member
{
public virtual int MemberId { get; set; }
public virtual string Username { get; set; }
public virtual bool IsActive { get; set; }
public virtual bool IsSame { get; set; }

[Code]....

View 3 Replies

MVC2: How To Render A View If Has Multiple Different Models

Dec 12, 2010

I know that view model can be used for rendering a view, but if a page needs different models, how can I pass them to the view? And how do I use them?

View 2 Replies

MVC :: Strongly Typed HtmlHelpers And View Models?

Oct 26, 2010

I am not sure why this happens, but when I have an Html.TextBoxFor(model => model.SomeObject.SomeProperty), when I post, the property of that object is always null.

When I look at the markup generated, I see <input type="text" name="SomeObject_SomeProperty" id="SomeObject.SomeProperty" value = "" />

If I change the helper to Html.TextBoxFor(model => model.SomeObject.SomeProperty, new {id = "SomeProperty"}) the controller is then able to pick the value up. Why is this happening? I feel as though I shouldn't have to be specifiying the id for the textbox as it works when fine when not using child objects on a view model, IE <%: HtmlTextBoxFor(model => model.SomeProperty) %>.

View 8 Replies

MVC :: Use Mutliple Models For One View Or Partial Views?

May 8, 2010

I've recently began learning ASP.NET MVC.I created my first project, and added a model via Linq TO SQL. The first model handled a database table that held a list of menu items.I then created a view and the view would loop through all of the menu items returned by the controller and build a custom menu for me.

I then created a Model via Linq TO SQL to point to a table that hold's my site articles.I created a view that would itereate through all of the site articles returned by the controller and list them in the view.

Now I've taken the logic from the menu view and created a partial usercontrol view to build my menu. I've done the same thing with the SiteArticles.

How do I make the data from both of these modles availble in one view?I basically want to HTML.RenderPartial("MenuControl") in my master page and RenderPartial("ArticleControl") in the conent of the view.

I'm using the original view that i created to show articles..

So If i remove the rendering of the menucontrol user control from the master page and i call the view to show the articles, the articles will render because the controller knows to load the articles and return them to the view..

If i add the menu user control to the masterpage, I get an error because the view recieves data from the site article model/controller but not from the menu model/controller.

View 3 Replies

MVC :: Create View Which Inherited From Couple Or More Models?

Apr 6, 2010

For example i need create page to display few models. Inherits property can take in only one value, as i mean.

[Code]....

I want something like:
[Code]...

View 8 Replies

MVC :: How To Reuse Model Metadata For Custom View Models

Oct 19, 2010

I'm working on an ASP.NET MVC 2 project with some business entities that have metadata dataannotations attributes applied to them (Validation attributes, Display attributes, etc.).

Something like:

[Code]....

Using the metadata from different views is no problem, as long as I am using my business entities as viewmodels or as part of a viewmodel like this:

[Code]....

However, sometimes I need to code a view for editing some, but not all fields of an entity. For those fields I want to reuse the metadata already specified in my user entity. The other fields should be ignored. I'm talking about custom view models like this:

[Code]....

That's where I am running into problems. The custom view model above leads to an exception when the view is generated, because it has no password property.

The associated metadata type for type 'Zeiterfassung.Models.ViewModels.Users.UserNameViewModel+UserModel' contains the following unknown properties or fields: Password. make sure that the names of these members match the names of the properties on the main type.

Also, even if this exception did not occur, I expect to get into even more trouble with model validation on form submit because Password is marked as required in my business entity.

I can think of several workarounds, but none seem really ideal. In any case I can't change the database layout so that the password field would be in a separate entity in my example above.

How would you handle this scenario?

View 3 Replies

MVC :: Data Annotations, View Models & Multiple Controller Actions?

Feb 17, 2010

quick question: I have a view on my HomeController which is used to create a new 'model'. This view posts to a different controller to keep things tidy. The problem I am having is when I enter invalid details into the form, the rules I specified never seem to make it back to the original view and thus my validation messages or summary never get populated. Is there a way around this because I am using a view model with two IEnumerable lists in it.

View 5 Replies

Accessing Details View Bind Data Before The View Is Rendered

Feb 25, 2011

I have a field in a details view shown below

<asp:BoundField DataField="DTMON_F" HeaderText="Monday Hours From: " InsertVisible="False"
ReadOnly="True" SortExpression="HOURS" Visible="false" />
<asp:TemplateField HeaderText="Monday Hours From: " SortExpression="HOURS">
<EditItemTemplate>
<uc1:TimePicker ID="tpMondayHours" runat="server"/>
</EditItemTemplate>
<InsertItemTemplate>
<%-- <uc1:TimePicker runat="server" ID="tpMondayHours" />--%>
<asp:TextBox ID="txtMondayHours" runat="server" Text='<%# Bind("DTMON_F") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="lblMondayHours" runat="server" Text='<%# Bind("DTMON_F") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Before "DTMON_F" is binded to the view I want to cut the string that is returned...Where and how might I do this?

View 1 Replies

Using The Item Template To Bind Values From 3 Dropdowns Into A Single Value?

Feb 24, 2011

I am using an asp.net details view. I added an entry into the details view like so...

<asp:BoundField DataField="DTMON_F" HeaderText="Monday Start:" InsertVisible="False"
ReadOnly="True" SortExpression="DTMON_F" Visible="false" />
<asp:TemplateField HeaderText="*Monday Start: " SortExpression="DTMON_F">
<EditItemTemplate>

[Code]....

Now I need to FIRST concatinate the values from the dropdown then bind the data gathered in the edit template form the 3 dropdowns. How might I do that?

View 2 Replies

Data Controls :: Bind Two DropDownList From Single XML File?

May 7, 2015

[URL] .I have two dropdownlist which i want to bind from only one xml file like below :

<?xmlversion="1.0"encoding="utf-8" ?>
<WeatherStatus>
<status>

[Code].....

Dropdownlist1 will only bind values of weatherstatus elements and Dropdownlist2 will only bind Windirections element.

View 1 Replies

Data Controls :: How To Bind Single Character To CommandArgument Of LinkButton

May 7, 2015

I want to pass single character passed when i clicked in the linkbutton.

and how i access this at code behind file.

View 1 Replies

How To Bind Single Field Of Grid With Multiple Values Using DataBinder.Eval

Jun 29, 2010

i have one hidden field and i want to bind it with two values of my data base separated by an coma. some thing like
->asp:HiddenField ID="hfRstidDate" runat="server" Value=<%# DataBinder.Eval(Container.DataItem, "tsk_ID"),DataBinder.Eval(Container.DataItem, "Date_Worked").ToString())%>

View 1 Replies

Forms Data Controls :: How To Bind Large Number Of Record At Single Click In C#

Nov 18, 2010

I have developed one simple application in that i am using mysql database. but my database size more thatn 4,50,0000, as well as ecah and every second my database is updated i.e record ll be added to the table how can i get the details for one single click.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved