0
테이블에있는 하나의 큰 모델에 대해 모두 편집 뷰를 만들고 싶지만 기본 정보, 연락처 정보 등에 대해서는 더 작은 모델이 있습니다. 정말 큰 내가 20 텍스트 상자 하나 개 편집 뷰를 작성하고 싶지 않아요. 그래서 여기ASP.NET MVC가 잘못된 액션 (매개 변수 없음)을 찾고 있습니다.
을 내가 parametr ID로 HttpGet
액션을 만드는 문제이며, 모델 HttpPost
. 그리고 나는 내 양식을 보내고있을 때 나는 오류 System.MissingMethodException
있어 , 나는 매개 변수가없는 Action 메서드가 없다. ..
Kontrahenci
은 테이블의 EF에서 내 모델이다. DaneOglneKontrahenta
은 도움이된다. 개미 클래스는 단지 6 변수 대신 20를 보내
[HttpGet]
public ActionResult EdytujDaneOgolne(int? id)
{
if (id == null)
{
Redirect("Index");
}
Kontrahenci kontrahent = db.Kontrahenci.Find(id);
if (kontrahent == null)
{
Redirect("Index");
}
DaneOglneKontrahenta model = new DaneOglneKontrahenta(kontrahent);
return View(model);
}
포스트 방법 :보기에 그런
[HttpPost]
public ActionResult EdytujDaneOgolne(int id, DaneOglneKontrahenta kontrahent)
{
Kontrahenci kontrahentModel = db.Kontrahenci.Find(id);
if (kontrahentModel == null)
{
Redirect("Index");
}
kontrahentModel.Nazwa = kontrahent.Nazwa;
kontrahentModel.NazwaSkrocona = kontrahent.NazwaSkrocona;
kontrahentModel.NIP = kontrahent.NIP;
kontrahentModel.Komentarz = kontrahent.Komentarz;
kontrahentModel.UwagiDS = kontrahent.UwagiDS;
kontrahentModel.UwagiZlecenie = kontrahent.UwagiZlecenie;
db.SaveChanges();
return View("Detalis");
}
: 당신은 그냥 컨트롤러 이름과 조치를 지정해야합니다
@using(Html.BeginForm())
{
//Some textboxes
<input type="submit" value="Create" class="btn btn-default" />
}
잘 trie 그 결과가 없으면 이전에,하지만 한 가지 내가 그때 내가 다른 오류있어 통고를 didnt했다. 그래서 그것은 작동하지만 나는 지금 막 두 가지 오류가 있음을 알 수 있습니다. 두 번째는 내가 paramets없는 모델에 대한 생성자가 없다는 것입니다. 이제 모든 것이 잘 작동합니다 – JJJ
@Jackob,'Html.BeginForm()'의 기본값은 POST입니다. 그래서 컨트롤러가 길고 동작이 현재 url에 있어야합니다. 매개 변수가없는 생성자가 없다는 오류는 action 메소드가 실행될 때 가장 먼저하는 일은'DaneOglneKontrahenta'를 만들고 POST에서 보낸 데이터로 채우려고하기 때문입니다. 내부적으로'new DaneOglneKontrahenta()'를 호출하고 그러한 메소드가 없기 때문에 충돌이 발생합니다. – derloopkat
그래, 나도 알아, 모든 일을 잘한다, 고마워. – JJJ