MVC how to fill form from different model - asp.net

I have table with Name,Surname, city and Address. (Model, View, Controler- strongly typed)
When I click on some record I want to open another form with
Name,Surname, city and Address and Parent name, but I need
Name,Surname, city and Address to be filled with data from record clicked.
Model is strongly typed.
It's need to be done with two models.
My question is- how to pass data from one model to another (the best way).

Related

Dropdown Widget and Related Model

I have two models, Country and City and a one-to-many relationship between them. One country can have many cities and a city can only have one country. App Maker generates a Country_fk field in the City model.
Now when I create a Create form and drop a form bound to the City model and include the related Country field App Maker creates a dropdown with the following:
options: #datasources.Country.items
value: #datasource.item.Country
Which, if I compare it with some example apps looks absolutely fine. However, I only get the Id of the related Country field not the country name field.
This has happened so many times with different models. I did once manage to create a relationship that worked, and it used the same datasource options and value values, but I can't for the life of me see why something so simple as this is so hard to do. it is so basic newbie stuff I'm beginning to give up on App maker.
You can use a little bit of help from the official documentation.
When you create a model, you can select the default display field. App Maker uses the default display field when it refers to a record in the model. A display field is commonly used for widgets that select a record, such as dropdowns.
Go to your model and make sure you select the proper display field. Something similar like in the image below.
You need to make the required field the 'Display Name' in the relevant model. Once you do this it will display as you want 👍

CountrySelect form field, pre-populate with a country

How can I default to populating the Select drop down list with a value, in this case it would be the country U.S.. We've removed other countries from the list but users are still required to select the one option.
In addition to a default value, the dependent fields would need to be populated. Currently in Intershop, selecting the country populates the State field. I would like to default to U.S. and have the State field already populated on the initial request, sans ajax calls.
You would have to modify some pipelines for this.
The webform it loads is based in the country code. Intershop gets the countrycode from the addressbo or as a parameter. See the ViewUserAccount-ChangeAddress : this pipeline is used in the ajax request to load the webform when u select a country. You could use the same logic to load the U.S webform (US) when the address has not been filled in yet.

Enter data in mother table using data from child tables

Hi all,
I have 3 tables in an access 2010 database:
Crew: CrewID; Name; Adres;...
Voyage: VoyageId; Voyage name; Departure harbour; Arrival harbour
Crewlist: CrewlistId, VoaygeId, CrewId, Rank
The VoaygeId and CrewId from the Crewlist table are linked (relation) to the autonumber ID's from tables 2 and 1.
My first and main question is: Upon boarding everyone has to ‘sign in’ selecting the voyage and there name, and assign them a roll (of to be donde by the responsible officer). How can I make a form that lets the users browse through the voyagenames and crewnames in stead of the ID’s uses in the ‘mother’ table (table 3: Crewlist)
2nd question: how can I make sure that someone isn’t enrolled twice for the same voyage (adding same voyagenumber and same crewId number in crewlist). This would preferably be blocked upon trying to add the same person a second time on a voyage.
To prevent duplicates in Crewlist, add a unique index to the table on both CrewId and VoyageId
It would be a good idea to add relationships and enforce referential integrity
You are now in a position to use the wizards to create a form based on Voyage and a subform based on CrewList with a combobox based on Crew
There are a number of refinements you could add.
Make sure you do not use reserved words like Name and do not put spaces in field names. You will thank yourself later.
See also create form to add records in multiple tables

Fill datatable based on user input

I have a SQL db that holds the records for my page. On my page I have a details view I want to populate with records from my db. I can populate the records just fine, I need to be able to populate in records based on a user selection from a drop box?
To clarify, on my main page I have a drop down list with years (ie. 2011, 2010, 2009), and a drop down containing account codes (ie. six-digit numbers). Based on what the user chooses for the year (for example 2010) and the what they choose for the account code (for example 123456) I want to populate the details view (which is on a seperate page) with only those records from 2010 and with the account code 123456??
Far far haven't seen a way to make it work?
To fill the DetailsView based on input from form controls is actually quite straightforward. You're basically using the controls to supply parameter values to plug into the WHERE clause of a select statement.
In essence, you define your SqlDataSource to take Control parameters.
There's also documentation here: http://msdn.microsoft.com/en-us/library/z72eefad.aspx
And an article with screenshots here: http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/using-parameterized-queries-with-the-sqldatasource-vb
If the details view is on a different page, you can do the same thing using QueryString parameters, but that leaves you open to tampering. (People changing the values in thequery string to get at records they shouldn't see.) If tampering isn't an issue with your specific situation - the data isn't sensitive in nature, then it shouldn't be an issue, but its' something to be aware of.

ASP.NET MVC Model Binding

I was wondering if there was a way to bind the value of an input field straight to the property in the Model through a strongly typed model. For example, let's say my Model is an Address object. I want to be able to say Html.Textbox(Model.Address1.State, "state", Model.Address1.State). So the first parameter would be the explicit property I want to bind to of the model with the value from the user, the second parameter would just be the DOM id, and the third value would be the initial value to input when I render the view.
I know you can do Html.TextBox("Address.State") and have a custom binder which would create the Address object for you and populate the state property. I need Html.Textbox(Model.Address1.State).
Help?
I think the FluentHtml stuff from the mvccontrib code is what you may want to check out.

Resources