Korzystam z gotowego szablonu aplikacji MVC w ASP i mam tam taki formularz:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Movie</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ReleaseDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReleaseDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ReleaseDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Genre, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Genre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Genre, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
No wszystko jest tu ładnie jasno i przejrzyście.. do momentu aż chciałem zrobić to sam i poszedłem z tym przykładem pisząc taki kod:
@using (Html.BeginForm())
{
@Html.EditorFor(model => model.companyName)
@Html.EditorFor(model => model.companyAdress);
@Html.EditorFor(model => model.companyMobilePhone)
@Html.EditorFor(model => model.companyPhone)
<input type="submit" value="Create" class="btn"/>
}
No i tutaj jest problem bo dane te nie są wysyłane do bazy danych? Dlaczego?
A dlatego, że nie podałem nazwy kontrolera i akcji, toteż pierwsza linijka powinna wyglądać tak:
@using (Html.BeginForm("Create","Managament",FormMethod.Post))
Moje pytanie dlaczego? Dlaczego w przykładowej aplikacji nie trzeba tego podawać a jak się to tworzy bez generatorów to już tak? Gdzie jest ta zależność?