0

我試圖從引導表單傳遞一些用戶輸入的數據,並將值推送到Visual Studio 2013中的MVC4項目中的模式,嘗試閱讀幾個主題,但嘗試我正在努力尋找一個簡單的答案。MVC + JQuery:將數據從文本字段傳遞到模式

我如何從我的自助表單元素中獲取一個值,並在模態內返回。我試圖從文檔中將JQuery添加到模態本身,但是我在這裏做了一些錯誤,誰能幫助解決這個問題?

表單元素:

<div class="form-group"> 
<label class="control-label col-xs-2" for="iMei">IMEI:</label> 
<div class="col-xs-9"> 
<input type="text" class="form-control" id="imei" name="imei" placeholder="IMEI"> 
</div> 
</div> 

<div class="form-group"> 
<label for="platform" class="control-label col-xs-2">Platform:</label> 
<div class="col-xs-10"> 
<div class="dropdown"> 
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1"  data-toggle="dropdown"> 
Select 
<span class="caret"></span> 
</button> 
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2"> 
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Android</a></li> 
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">IOS</a></li> 
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Windows Phone</a> </li> 
</ul> 
</div> 
</div> 
</div>   

我的模態:

<div class="form-group"> 
<div class="col-xs-offset-2 col-xs-10"> 
<a href="#" class="btn btn-success" 
          data-toggle="modal" 
          data-target="#basicModal">Create New Request</a> 
<button type="submit" class="btn btn-primary">Back to List</button> 
        </div> 
       </div> 


<div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true"> 
       <div class="modal-dialog"> 
        <div class="modal-content"> 
         <div class="modal-header"> 
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button> 
          <h4 class="modal-title" id="myModalLabel">Summary</h4> 
         </div> 
         <div class="modal-body"> 
          <script> 
           $('#basicModel').on('show.bs.model', function (e) { 
            var imei = 
            $(e.relatedTarget).data('imei'); 
           }); 
          </script> 
         </div> 
         <div class="modal-footer"> 
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
          <button type="button" class="btn btn-primary">Save changes</button> 
         </div> 
        </div> 
       </div> 
      </div> 
+0

我看不到您的表單被包裝在

元素中的任何實例?如果你點擊Save Changes按鈕,那麼這個表格將不會提交?我會建議[看看這個教程](http://blog.michaelckennedy.net/2012/01/20/building-asp-net-mvc-forms-with-razor/),它解釋瞭如何在ASP.NET MVC – 2014-09-04 11:10:26

+0

嗨喬,有一個表單元素我剛剛採取了2/6元素,以避免在這裏全長代碼。 – Baggerz 2014-09-04 12:28:04

+0

它發佈什麼路徑,並且可以發佈接收請求的控制器/操作方法? – 2014-09-04 13:11:51

回答

0

在最後,我使用了下列溶液:

Jquery的發送形式的數據

$("#SendRequest").click(function() { 
     var imei = ("IMEI: " + $("#imei").val()); 
     $('#printImei').html(imei); 

     var phonenumber = ("Phone Number: " + $("#phoneNumber").val()); 
     $('#printPhoneNumber').html(phonenumber); 

     var policynumber = ("Policy Number: " + $("#policyNumber").val()); 
     $('#printPolicyNumber').html(policynumber); 
    }); 

而在莫代爾Body

<div class="modal-body"> 
    <span id="printImei"></span><br /> 
    <span id="printPhoneNumber"></span><br /> 
    <span id="printPolicyNumber"></span> 

</div> 
相關問題