2017-09-13 49 views
0

我有我的.cshtml页面链接到一个SSRS报告:追加输入字段值的URL上.cshtml页

<div class="col-md-8"> 
 
    <a href="http://xxx.xx.xx.x/ReportServer/Pages/ReportViewer.aspx?%2fCompany_Reporting%2fpayr0001&rs:Command=Render&StartDate=01/09/2017" target="_blank" >Timesheet Status Report</a> 
 
</div>

我需要从传递值我日期控制作为相对于上述硬编码日期的参数:

<div class="form-group"> 
 
    <input type="date" class="form-control" id="datefrom"> 
 
</div>

我曾尝试追加一个onclick=myfunction()到URL添加日期值,但无法让它工作。

function getStartDate() { 
    return document.getElementById("datefrom").value; 
} 

任何帮助将不胜感激。

干杯。

+1

你可以显示你试图添加的onclick函数吗? – PredatorIWD

+0

这是什么'myfunction()'做的?只是发布HTML不会让我们知道实际发生的情况 – Se0ng11

+0

Kathleen

回答

1

在日期更改属性中创建锚标记的href。在旅途中构建href。

$('#datefrom').change(function(){ 
    $('#IdOfAnchorTag').attr('href','http://xxx.xx.xx.x/ReportServer/Pages/ReportViewer.aspx?%2fCompany_Reporting%2fpayr0001&rs:Command=Render&StartDate=' + $('#datefrom').val()); 
}); 

检查相应的字符串..

+0

'IdOfAnchorTag'表示锚标签的id。好的......但在OP代码中没有'id'。编辑你的答案;)我的意思是......解释。 (大声笑)你知道OP想要做什么,我想。 –

+0

哈哈..常见..它会有一个Id,类名.. ..东西..考虑到他给的数据,我想它会在那里。 – Sameer

0

这是你想要做什么,据我可以告诉(重复的问题?):
append to url and refresh page

为了获取日期在正确的格式中,您必须在功能正文中执行以下操作:
new Date($('input[type=date]').val()).toLocaleFormat();

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat

另外,您可能要为日期输入使用'onblur'/ blur事件,或者将事件处理函数连接到专门用于该目的的新按钮。这是因为点击日期输入(可能打开某种日历小部件,取决于浏览器和浏览器版本),onclick/click事件就会触发。

0

在将日期值传递给网址之前,请尝试将日期转换为dd-MM-yyyyMM-dd-yyyy而不是dd/MM/YYYY。 因为我认为当url会误解“/”,所以你应该用“ - ”替换。 然后如有必要,您可以转换回旧的格式。