簡體   English   中英

我無法在MVC 4 C#中的視圖上獲得文本框的值

[英]I can not get the value of a textbox on a view in mvc 4 C#

@model IEnumerable<TBWeb.Models.SP_GetALlRoutes_Result>

@{
    ViewBag.Title = "Rutas";

    Layout = "~/Views/Shared/_Layout.cshtml";

   string fecha=string .Empty ;
 }


<script language="JavaScript" type="text/JavaScript">
    $('#FechaInicio').onchange(function (){

     fecha= document.getElementById("FechaInicio").value;

    )};
  </script>


<input type="text" id="FechaInicio">
@model IEnumerable<TBWeb.Models.SP_GetALlRoutes_Result>

@{
    ViewBag.Title = "Rutas";    
    Layout = "~/Views/Shared/_Layout.cshtml";
 }

<input type="text" id="FechaInicio">

<script language="JavaScript" type="text/JavaScript">
$(function() { //wait for doc ready before trying to wire up to element

    //use jquery event handler for text change: 'input' event is an on change event 
    $('#FechaInicio').on('input', function (){

       var inicio = $(this).val();//this refers to the FechaInicio element the input event fired on

       //send to controller action
      $.ajax({
        url: @Url.Action("SomeActionName"),
        type: 'POST',
        data: { 
          whateverParamNameIsIncontrollerAction: inicio 
        },
        success: function (result) {
           //do whatever after request completes
        }
      });//ajax           

    )};//on input

)};//doc ready
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM