我的埃德特形式,在挽救结果时存在问题。
观点:
<div class="editor-label">
@Html.LabelFor(model => model.LoginModel.Uzytkownik)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LoginModel.Uzytkownik)
@Html.ValidationMessageFor(model => model.LoginModel.Uzytkownik)
</div>
模式:
namespace Restauracja.Models
{
public class pracownikModel
{
public LoginModel LoginModel { get; set; }
public uzytkownikModel uzytkownikModle { get; set; }
public pracownikModel() {
LoginModel = new LoginModel();
uzytkownikModle = new uzytkownikModel();
}
}
public class LoginModel
{
[Required]
public string Uzytkownik { get; set; }
[Required]
public string Haslo { get; set; }
public string Konto { get; set; }
}
public class uzytkownikModel
{
[Required]
public string imie { get; set; }
....
}
}
主计长:
[HttpGet]
public ActionResult Edit(int LoginID)
{
pracownikModel prac = new pracownikModel();
var pr = (from p in baza.Logowanies where LoginID == p.LoginID select p).First();
prac.LoginModel.Uzytkownik = pr.Login;
return View(prac);
}
[HttpPost]
public ActionResult Edit(int LoginID, pracownikModel prac)
{
var xxx = (from z in baza.Logowanies where LoginID == z.LoginID select z).Single();
xxx.Login = prac.LoginModel.Uzytkownik;
baza.SubmitChanges();
return RedirectToAction("Index", "Foo");
}
Function with [HttpGet] is working properly, showing result from database. The problem is with second function... prac is null... So this cannot work because I can t write null to the database. I don t know how to solve this problem.