简体   繁体   English

MVC ASP.Net Javascript-如果Url没有ID,如何使用JavaScript函数隐藏按钮

[英]MVC ASP.Net Javascript - How do I use a javascript function to hide a button if Url has no id

Here is my Javascript code that goes to the url with the correct id from model but I am not sure how to hide it if the url has no model id. 这是我的Javascript代码,该URL具有来自模型的正确ID的url,但是如果该URL没有模型id,我不确定如何隐藏它。

 function lnkBack_Confirm() {
    var bResponse = confirm('Are you sure you want to go back to the Details Page?');

    if (bResponse === true) {
        ////console.log("lnkBack_Confirm clciked.");
        var url = '@Url.Action("NewHireDetails", "Home", new { id = Model.ID })';
        window.location.href = url;
    }

    return bResponse;
}

All I would like to do is hide it if the url has no id = Model.ID. 我只想隐藏它,如果url没有id = Model.ID。 I am not sure how to do this. 我不确定该怎么做。 Can someone please help. 有人可以帮忙吗? Thanks in advance. 提前致谢。

you can look at model values in your script. 您可以在脚本中查看模型值。 something like this should work for you 这样的事情应该为您工作

$(document).ready(function(){
    if('@Model.ID' == ''){
        $('.btnClass').hide();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM