1

So im writing an application that has an upload Area for images..

What I would like to do is Dynamicallyi build a path for files that are to be uploaded.

The User would select a Client,Market,Project and Place ( all of these are Seperate Models )

I would like to build a View that Showed Clients( dropdown), Market (dropdown) and so on so i can then grab those values to place them on the Server under a directory in that name...

I do not know how to combine my models to get them all into a Single view, other then creating a partial view for every dropdown menu ( is this the right way to handle this ? )

Can anyone Help? - Thanks

EDITS :

Here is what i was thinking you ment i could throw into a Razor View ( givin i pass all of them somehow )

@model OilNGasWeb.Models.UserProfiles
@model OilNGasWeb.Models.UserInfo
@model OilNGasWeb.Models.UserData
@model OilNGasWeb.Models.Users

then some code beneath ... thats what you ment with Hierarchie?


what i was thinking is to include the IEnumerable<> in the model of say the Main Model Was Users

User Model

[Table("Users")]
public class UserProfiles
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]

    public int UserId { get; set; }

    public string UserName { get; set; }

    public virtual ICollection<UserRoles> UsersRoless { get; set; }
    public virtual ICollection<UserInfo> UsersInfos { get; set; }
    public virtual ICollection<UserData> UsersDatas { get; set; }
    public virtual ICollection<Users> Userss { get; set; }

then do partial views for each in the index view of Users...

Trying to think of a better concept ( if there is one ) sorry for making the question unclear

4
  • A model can be hierarchical, so why not add those other models as properties of the root view model? Commented Jul 19, 2013 at 16:17
  • @BrianMains What do you mean , like in the view : @ model og.UserProfiles and then next line like @ model og.UserRoles and then @ model og.UserInfo????? Commented Jul 19, 2013 at 16:51
  • Yes, possibly... Could you include some code to help us see what you are trying to do? Commented Jul 19, 2013 at 17:41
  • Sorry for not explaining, this is all trying to find the best concept, nothing is written yet. I would like to find / think about the best way to code before coding. look above edits for what i was trying to say in the coment above Commented Jul 19, 2013 at 17:45

1 Answer 1

3

You can't have many models like that, but you can do:

public class RootModel
{
  public Ienumerable<UserProfile> Profiles { get; set; }

  public UserInfo User { get; set; }

  public Ienumerable<User> Users { get; set; }

  .
  .
}

And then pass this to your complex view. You can pass the data to partial views by supplying the model property of the Html.Partial("X", Model) form of the method.

Sign up to request clarification or add additional context in comments.

2 Comments

Alright thanks, I was jsut curious if there was a better way of doing this. Thanks for the response. Also on an unrelated side, if you don't mind, Can i use the same princible and the entity framework will know where to store what data ( say i use this concept for an edit? )
As long as all the data comes from the same context, you can then use it for an edit. However, the object context lives only for the current request (unless you store it as a static, but then you have other problems) so it depends what you mean. You can use the same principal, but if you load an edit form, then render, then save the change, this can be a little more complicated and requires some "care". The best thing I can say is give it a shot, and write another question if it doesn't work :) It's always a good learning experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.