2014-10-29 194 views
0

我需要在点击按钮后将@ html.label的值传递给控制器​​“Verificar”的变量“data”。将html.label的值传递给控制器​​

我所做的:

@Html.Label("modalTitle", new { id = "modalTitle" }) 
<button type="button" class="btn btn-defaultgreen" onclick="location.href = '@Url.Action("Verificar", "Feriado", new { date = @Html.Label("modalTitle", new { id = "modalTitle" }).toString() }, null)'">Create Event</button> 

,但没有工作这种方法....需要你的帮助!感谢

+0

你是什么意思“@ Html.Label的价值”?标签不是输入。从你提供的例子看来,你想要标签的标记,但为什么? – 2014-10-29 22:41:58

+0

becouse我在javascript中使用FullCalendar v1.6.4:case“select”>> $('#modalTitle')。html(start.toString()。substring(0,15));将日期传递给@ html.label。现在我需要把这个日期传给我的控制器。 – 2014-10-29 22:53:44

+0

'@ Html.Label()'给你的财产的名称,而不是它的值(我假设的日期)。包含您想要传递给控制器​​的日期的控件是什么? – 2014-10-29 23:02:31

回答

0

更改日历功能添加数据属性对标签的数据属性设置数据:

$('#calendar').fullCalendar({ 
       editable: false, 
       events: "/Reglamento/GetEvents/", 
       selectable:true, 
       select: function(start, end, jsEvent, view) { 
        //Bootstrap modal 
        $('#modalTitle').html(start.toString().substring(0, 15)); 
        //Add data attribute - can have better date format here (e.g. yyyy-MM-dd) 
        $('#modalTitle').data("startdate", start.toString().substring(0, 15); 
        $('#fullCalModal').modal(); 
       } 
      }); 

更新您的按钮来调用抓住数据属性的功能,构建网址和设置位置:

function NavigateByDate() 
{ 
    var date = $('#modalTitle').data("startdate"); 

    //this could be done better...should show the intention though 
    var url = '@Url.Action("Verificar", "Feriado")' + '?data=' + date; 
    location.href = url; 
} 
+0

你好,我不明白这一行>> var url ='@ Url.Action(“Verificar”,“Feriado”'+'?data ='+ date'; – 2014-10-30 02:20:31

+0

这就是根据这个动作生成你的url你正在运行,并且通过了添加到标签的数据属性中的日期。 – 2014-10-30 02:21:30

+0

应该是这个?? var url ='@ Url.Action(“Verificar”,“Feriado”)'+'?data = '+日期; – 2014-10-30 02:22:34