Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在MVC4C中,我无法获取视图上文本框的值# @model IEnumerable @{ ViewBag.Title=“Rutas”; Layout=“~/Views/Shared/_Layout.cshtml”; string fecha=string._C#_Asp.net Mvc - Fatal编程技术网

C# 在MVC4C中,我无法获取视图上文本框的值# @model IEnumerable @{ ViewBag.Title=“Rutas”; Layout=“~/Views/Shared/_Layout.cshtml”; string fecha=string.

C# 在MVC4C中,我无法获取视图上文本框的值# @model IEnumerable @{ ViewBag.Title=“Rutas”; Layout=“~/Views/Shared/_Layout.cshtml”; string fecha=string.,c#,asp.net-mvc,C#,Asp.net Mvc,在MVC4C中,我无法获取视图上文本框的值# @model IEnumerable @{ ViewBag.Title=“Rutas”; Layout=“~/Views/Shared/_Layout.cshtml”; string fecha=string.Empty; } $('#FechaInicio').onchange(函数(){ fecha=document.getElementById(“FechaInicio”).value; )}; @model IEnumerable @{ Vi

在MVC4C中,我无法获取视图上文本框的值#
@model IEnumerable
@{
ViewBag.Title=“Rutas”;
Layout=“~/Views/Shared/_Layout.cshtml”;
string fecha=string.Empty;
}
$('#FechaInicio').onchange(函数(){
fecha=document.getElementById(“FechaInicio”).value;
)};
@model IEnumerable
@{
ViewBag.Title=“Rutas”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
$(函数(){//在尝试连接到元素之前,请等待doc就绪
//将jquery事件处理程序用于文本更改:“input”事件是一个on change事件
$('#FechaInicio')。on('input',function(){
var inicio=$(this).val();//这是指触发输入事件的FechaInicio元素
//发送到控制器操作
$.ajax({
url:@url.Action(“SomeActionName”),
键入:“POST”,
数据:{
控制作用:inicio
},
成功:功能(结果){
//在请求完成后做任何事情
}
});//ajax
)};//输入时
)};//医生准备好了吗

Este es mi文本框您的代码在逻辑上有缺陷<代码>字符串fecha=string.Empty是一个C#变量,但是JavaScript块中的
fecha
是一个JavaScript变量。您无法从JavaScript向C#赋值,因为C#在服务器上运行,在客户端运行JavaScript时已消失。如何在变量中获取此值???您希望将变量发送回服务器还是仅在JavaScript中可用?我希望将变量的值作为参数发送,以调用需要的控制器这个值。
@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>