Reputation: 1271
I have done some projects on MVC. I have a generic doubt.
Can view create objects of model class in MVC pattern? For example, lets say we are designing MVC for taxi management system. We have classes for cab and passenger. View will be taking passenger and cab details from user.
can we instantiate cab and passenger(model class) in view for storing details?
If we cant instantiate then where should we store details after taking from user?
How will it pass to controller?
I am new to MVC and any help will be greatly appreciated. I have googled it many times but have not got the satisfactory answer.
Upvotes: 2
Views: 431
Reputation: 1362
View HTML
<div class="registrationForm">
@using (Html.BeginForm("Registration", "Car", FormMethod.Post))
{
<p>
<input type="text" name="carName" placeholder="Your Car Name" />
</p>
<p>
<input type="text" name="carNum" placeholder="Re-enter Number" />
</p>
<p>
<input name="signup" type="submit" value="Submit">
</p>
}
</div>
Controller Action
public ActionResult Registration(String carName, string carNum)
{
// your logic
return View();
}
Please modify if I am wrong.
Upvotes: 2