obiekt view model
public class DokumentPzViewModel
{
public int nrMagazynu { set; get; }
public String nazwaMagazynu { set; get; }
public int nrDostawcy { set; get; }
public String nazwaDostawcy{ set; get; }
public long testId { set; get; }
public int? wybranyMagazynId { set; get; }
public int? wybranyDostawcaId { set; get; }
public DokumentPzNaglowekDTO NaglowekPzDTO { get; set; }
public List<DokumentPzPozycjaDTO> PozycjePzDTO { get; set; }
public List<MagazynDTO> MagazynyDTO { get; set; }
public List<DostawcaDTO> DostawcyDTO { get; set; }
}
pole testId ustawiam na 10
public ActionResult Create()
{
......
mDokumentPzViewModel.testId = 10;
return View(mDokumentPzViewModel);
}
wysyłam do pliku cshtml o kodzie
@model HurtowniaWebMVC.DokumentPzViewModel
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
....................................................
<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>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
w kontrolerze w tej funkcji odczytuję w debugerze wartość pola testId = 0 zeruje go bez żadnych zmian w polu w pliku cshtml
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "NaglowekPzDTO,wybranyMagazynId,wybranyDostawcaId,testId")] DokumentPzViewModel mDokumentPzViewModel)
{
if (ModelState.IsValid)
{
............
return RedirectToAction("Index");
}
return View(mDokumentPzViewModel);
}