2014-10-29 199 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