2011-07-01 5 views
0

이 코드 출력은 버튼을 클릭 할 때 표시되는 텍스트 상자에 내용을 입력하는 것입니다. 하지만 내가 원하는 때 확인란을 선택하고 텍스트 상자에 입력 된 값을 입력하고 싶습니다.JQuery/Ajax-MVC2를 사용하여 버튼 클릭 이벤트로 확인란을 사용하는 방법

//View page: In this page JQuery for request&Responce type and i am displaying two text box and 1 check box and 1 button 

<script type="text/javascript"> 

    $(function(){ 
     $('#selectAll').change(function() { 
      alert("value changed");//When i run this script only witht this alert function i am getting output but with this code i am unable to get the output what i expect 

      var options = { 
     target: '#result-user', // id of the div where we are going to display result 
       beforeSubmit: showRequest, 
       success: showResponse, 
       type: 'post', 
       resetForm: true 
      }; 
      $('#form-user').ajaxForm(options); // id of the form we wish to submit 
     }); 
    }); 


     function showRequest(formData, jqForm, options) { 
      $("#result-user").empty().html('Loading....'); 
      $("#form-user :input").attr("disabled", true); // disable all form inputs while loading 
     } 



     function showResponse(responseText, statusText, xhr, $form) { 
      $("#result-user").empty().html(responseText); 
      $("#form-user :input").attr("disabled", false); 
     } 
    </script> 
</head> 

<body> 

    <% using (Html.BeginForm("Index","Home",FormMethod.Post, new { id="form-user", name="form-user"})) {%> 

     <fieldset> 
      <legend>Fields</legend> 
<div class="editor-label"> 
       <%= Html.LabelFor(model => model.FirstName) %> 
      </div> 
      <div class="editor-field"> 
       <%= Html.TextBoxFor(model => model.FirstName) %> 
       <%= Html.ValidationMessageFor(model => model.FirstName) %> 
      </div> 
     <div class="editor-label"> 
       <%= Html.LabelFor(model => model.LastName) %> 
      </div> 
      <div class="editor-field"> 
       <%= Html.TextBoxFor(model => model.LastName) %> 
       <%= Html.ValidationMessageFor(model => model.LastName)%> 
      </div> 
      <div> 
      <input type="checkbox" name="selectl" value="ON" id="selectAll"/> 
      </div> 
      <p> 
       <input type="submit" value="Save" /> 
      </p> 

제어 페이지 코드의

public class HomeModel 
{ 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 

} 

실제 출력 버튼을 쳤을 때 내용이 텍스트 상자에 입력 표시하는 것입니다

public class HomeController : Controller 
{ 
    // 
    // GET: /Home/ 

    public ActionResult Index() 
    { 
     return View(); 
    } 

    [HttpPost] 
    public ActionResult Index(HomeModel data) 
    { 
     return Content("You submitted: " + data.FirstName + " " + data.LastName); 

    } 

} 

모델 페이지. 하지만 출력 싶어요 whe 텍스트 상자에 입력 한 내용을 렌더링해야하는 checkBox를 선택합니다.

친구를 도와주세요.

답변

0

ajaxForm은 양식을 제출하지 않습니다. 제출 단추를 클릭하면 아약스를 통해 제출하도록 양식을 설정합니다.

변경 ajaxForm(options)에서 ajaxSubmit(options)으로 변경하십시오. 그 트릭을해야합니다 (그냥 시도하고 그것을 작동). 운이

+0

죄송합니다 .. 저를 제안하십시오 .. – User1234

+0

내가 내 체크 박스에 어떤 변화가 말 그대로 새로운 MVC 솔루션에 코드를 붙여 넣기/복사하여이를 발견

User1234

+0

속성 어떻게해야합니까. ajaxForm을 ajaxSubmit으로 변경하면 찾고 있던 동작이 발생했습니다. – rossipedia

관련 문제