将jquery-datetimepicker.js与MVC EditorFor

时间:2016-08-26 02:41:40

标签: javascript c# jquery asp.net-mvc

我已经从NuGet添加了XDSoft的jquery-datetimepicker,但是在渲染视图时遇到了很多麻烦。

我最终尝试从http://xdsoft.net/jqplugins/datetimepicker/(包的页面)和http://www.codeguru.com/csharp/.net/net_asp/a-jquery-ui-based-date-picker-for-asp.net-mvc-5.html(用于jquery-UI包,但有更多的通用帮助)一起拼凑一些指令但是不能为我的生活弄清楚我哪里出错了。

在BundleConfig.cs中,我添加了:

    // datetime picker
    bundles.Add(new ScriptBundle("~/bundles/datetime").Include(
        "~/Scripts/jquery.datetimepicker.js"));
    bundles.Add(new StyleBundle("~/Content/datetime").Include(
        "~/Content/jquery.datetimepicker.css"));

然后在_Layout.cshtml中,我添加了:

    @Styles.Render("~/Content/datetime")

    @Scripts.Render("~/bundles/datetime")

为了更好地衡量,在进行问题排查时,我尝试将这些内容直接添加到相关视图中,该视图基于创建视图的模板。

所以我的理解是,我必须做的就是将控件上的类设置为" datetime"。这不起作用(显示为普通文本框)。

然后我也尝试使用@Html.TextBoxFor(),但也无济于事。如果我改为将类更改为xdsoft_datetimepicker,则会留下空白而不是创建文本框,但显然仍然不是我想要的。

任何指针,或指向完整教程的链接(不是像https://cuteprogramming.wordpress.com/2015/08/29/jquery-plugins-xdsoft-datetimepicker-and-jssor-slider/这样的假设知识,它提到了添加功能,而没有说明我在哪里添加它或如何)为模型上的DateTime属性显示(浏览器不可知)日期时间选择器将不胜感激。

1 个答案:

答案 0 :(得分:0)

我还使用了您使用的codeguru网站上的public class DownloadFile { public SFTPChannel getSFTPChannel() { return new SFTPChannel(); } public void downloadFile(String srcPath, String dstPath, String fileName) throws Exception { DownloadFile test = new DownloadFile(); Map<String, String> sftpDetails = new HashMap<String, String>(); // Set host, port, user name, password sftpDetails.put(SFTPConstants.SFTP_REQ_HOST, "172.16.1.180"); sftpDetails.put(SFTPConstants.SFTP_REQ_USERNAME, "v01uc"); sftpDetails.put(SFTPConstants.SFTP_REQ_PASSWORD, "v01uc"); sftpDetails.put(SFTPConstants.SFTP_REQ_PORT, "22"); SFTPChannel channel = test.getSFTPChannel(); ChannelSftp chSftp = channel.getChannel(sftpDetails, 60000); String src = srcPath + fileName; Vector<ChannelSftp.LsEntry> obj = chSftp.ls(src); ArrayList<ChannelSftp.LsEntry> iList = new ArrayList<ChannelSftp.LsEntry>(); for (int i = 0; i < obj.size(); i++){ iList.add(obj.get(i)); } Collections.sort(iList); int index = obj.size() - 1; String sFile = srcPath + iList.get(index).getFilename(); String dst = dstPath + iList.get(index).getFilename(); OutputStream out = new FileOutputStream(dst); try { chSftp.get(sFile, out); } catch (Exception e) { e.printStackTrace(); } finally { chSftp.quit(); channel.closeChannel(); } } } 。调试时检查refjs文件是否正确加载。如果没有,请在css中使用直接链接引用,而不是捆绑。