2014-07-20 1 views
0

에 texboxfor <> 값을 게시하지 않습니다. 내 actionresult에서 submit 버튼을 클릭하면 호출되지만 매개 변수는 model.Soru라는 모델에서 모두 비어 있습니다.MVC 4 제출 버튼은 [httppost] 메소드

내 Soru() 생성자와 같은 모든 속성을 보냅니다. 빈 문자열 또는 int 인 경우 0입니다. textboxfor <> 값을 게시 할 수 없어도 볼 수있는 텍스트 상자 값을 편집합니다.

누구나 아이디어가 있습니까?

@Html.TextAreaFor(m => m.SoruIcerik, new { @name = "soruIcerik", @id = "soruIcerik", @rows = "10", @cols = "80" }) 

다음과 같이해야한다 :

public class Soru 
{ 
    public int ID; 
    public string Ad; 
    public string SoruIcerik; 
    public string Cevap; 
    public int Sira; 

    public Soru() 
    { 
     ID = 0; 
     Ad = string.Empty; 
     SoruIcerik = string.Empty; 
     Cevap = string.Empty; 
     Sira = 0; 
    } 
} 

// 여기에 당신은 여기에 잘못된 구문을 작성했습니다

@model X.Models.Soru 
@{ 


using (Html.BeginForm()) 
{ 
    <div class="col-md-7"> 

     @Html.TextAreaFor(m => m.SoruIcerik, new { @name = "soruIcerik", @id = "soruIcerik", @rows = "10", @cols = "80" }) 

    </div> 
    <div class="col-md-5"> 
     <div class="col-md-4 formSatiri"> 
      <label class="formSatiri"> 
       Soru Adi : 
      </label> 
     </div> 
     <div class="col-md-8"> 
      @Html.TextBoxFor(m=>m.Ad, new { @class = "formSatiri" }) 
     </div> 
     <div class="col-md-4 formSatiri"> 
      <label class="formSatiri"> 
       Cevap : 
      </label> 
     </div> 
     <div class="col-md-8"> 
      @Html.TextBoxFor(m => m.Cevap, new { @class = "formSatiri" }) 
      </div> 
     <div class="col-md-12 formSatiri"> 
      <input type="submit" class="btn btn-primary btn-sm pull-left" value="Kaydet"/> 
     </div> 
    </div> 
} 

} 

답변

2

컨트롤러

[ValidateInput(false)] 
    [HttpPost] 
    public ActionResult Index(Models.Soru form) 
    { 

     return null; 
    } 

//와도이다 :

@Html.TextAreaFor(m => m.SoruIcerik, new { @name = "SoruIcerik", @id = "SoruIcerik", @rows = "10", @cols = "80" }) 

이름과 ID는 "SoruIcerik"속성 이름과 일치해야하는 "soruIcerik"이었습니다.

또는 당신은 단순히 다음과 같이 쓸 수 있습니다 : 컨트롤이 같은 html로 뭔가를 렌더링

@Html.TextAreaFor(m => m.SoruIcerik, new {@rows = "10", @cols = "80" }) 

: 여기

<textarea id="SoruIcerik" name="SoruIcerik" rows="10" cols="80"></textarea> 

이름과 ID가 모델에 정의 된 속성과 동일해야합니다 .

속성으로 클래스 변수를 만들어야합니다. 좋아요 :

public class Soru 
{ 
    public int ID {get;set}; 
    public string Ad {get;set}; 
    public string SoruIcerik {get;set}; 
    public string Cevap {get;set}; 
    public int Sira {get;set}; 
} 
+0

예. 그렇지만 중요하지 않습니다. textarea가 틀리면 적어도 다른 textboxfor <> 값을 컨트롤러에 게시해야한다고 생각하지 마십시오. 하지만 제 모델은 방금 만든 것처럼 비어 있습니다. – Burk

+1

클래스 변수를 Properties로 설정해야합니다. 좋아요 : public int ID {get; set}; 공개 문자열 Ad {get; set}; – AmanVirdi

+0

다음 링크를보십시오 : http://www.codeproject.com/Articles/710776/Introduction-to-ASP-NET-MVC-Model-Binding-An-Absol – AmanVirdi