Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a question which i think might be better to take advice on rather than starting implementing it. So i have a class which is basically Generated By entity framework and that class will be used to save the data from the User. Now i have 3 classes which will be used to implement Cascading Drop down list in my Create.cshtml.
So
C#
public class Form
{
public int Id {get; set;}
public string Country {get; set;}
public string state {get; set;}
public string city {get; set;}
public string Name {get; set;}
public string Email {get; set;}
}

public class Country
{
public int CountId {get; set;}
public string Country {get; set;}
}

public class State
{
public int stateId {get; set;}
public string State {get; set;}
public int CountId {get; set;}
}

public class City
{
public int Id {get; set;}
public string City {get; set;}
public int stateId {get; set;}
}


As you can see their is one to many relationship between Country --> state and State --> city.
The Form class is basically used to fill the form from the user like a registeration form something of that sort.

Now i create strongly typed View against Form class but the problem is their is no way get the Country, State, City property from their Fields and i do not want to add fields to my Form Class because my database save only these fields.So i created another class ClassForRealform (What i know is this technique is called as MVVM or View model)

C#
public class ClassForRealform 
{
<pre>public int Id {get; set;}
public string Country {get; set;}
public string state {get; set;}
public string city {get; set;}
public string Name {get; set;}
public string Email {get; set;}

public virtual List<Country> countries {get; set;}
public virtual List<state> states {get; set;}
public virtual List<City> cities {get; set;}
}

Now bind my form to this class

now i add an controller action method let's say "Save"

public actionresult Save(Form form)
{
//Code to save
}

Now my question is can i do this binding my view to another class and passing data to another class and thus [populating the fields required? hope i make myself clear here


2. one more thing thats little out of line
How to place an empty label using html.label("",new {id ="label1" })
like this but above do not work
Posted
Updated 23-Jul-15 21:32pm
v2

1 solution

The project always should provide the code optimization techniques and performance then only the application occupy low space in server and provide the better performance.

For that when ever we want to use number of dependency related properties then we should maintain only one class which we have maintained in our code as Model.

The main purpose of this is object initialization and destroying will happen for only single class.

So better to reduce different classes for same properties with in same view.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900