I have a situation that I cannot find an answer for.
I have a model, say for a tour guide, that contains the name, address and other details about the guide.
With that model, there is a list of visitors that will accompany the guide.
The user completes the guide datafields then I display a page with the fields for adding the visitors.
At this point I have not posted anything yet, the data is still in the DIV for the guide.
How do I dynamically populate this list within the model, then post the entire model to the controller?
I've looked at the jQuery 'load' and 'post' and 'get' stuff, as well as the partial view methods and I'm still lost as to how to do this simple thing.
I have the page or Guide.cshtml like this, for example:
@model TourModel
<div id="guide">
<table>
<tr>
<td>Full Name</td>
<td>@html.TextBoxFor(m => m.FullName)</td>
// address for guide
<input type="button" id="Next" value="Next" onclick="AddVisitors()"
</div>
<div id="visitors" style="display:none">
<table>
<tr>
<td>Full Name</td>
<td>@html.TextBoxFor(m => m.visitors.FullName)</td>
//details for each visitor
</table>
<table>
@if (model.visitors.count > 0)
{
foreach (var vis in model.visitors)
{
<tr>
<td>@vis.FullName</td>
//etc for each visitor2
}
}
<script type="javascript">
function AddVisitors() {
$("#guide").hide();
$("#visitors").show();
}
</script>
What should the jQuery do, if I should use jQuery, to add the visitor to the List to the model?
Here are my models:
public class TourModel
{
public string guidename;
public string guideaddress;
public List<Visitor> visitors;
}
public class Visitor
{
public string visitorname;
public string visitoraddress;
}