如何根据审定的ActionLink之前给用户的确认消息 [英] How to give user confirmation message before ActionLink based on validation

查看:123
本文介绍了如何根据审定的ActionLink之前给用户的确认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下链接。点击之后,我想检查item.primary_company字段,如果填充,给用户一个警告,并询问他们是否想继续。我怎样才能做到这一点?

 < A HREF =<%= Url.Action(激活,新{ID = item.company_id})%GT;类=FG =按钮FG-按钮图标独奏UI状态默认UI的角落都><跨度类=UI图标UI图标刷新>< / SPAN>< / A>

修改

我已经改变了这一点,但点击时没有任何反应。另外,我不知道该如何引用该项目做的primary_company现场检查。我只想消息显示,如果item.primary_company.HasValue。我也想显示item.company1.company_name在确认消息。

 < A HREF =#的onclick =返回Actionclick(<%= Url.Action(激活,新{ID = item.company_id})%GT ;);类=FG =按钮FG-按钮图标独奏UI状态默认UI的角落都><跨度类=UI图标UI图标刷新>< / SPAN>< / A>
<脚本类型=文/ JavaScript的>
功能Actionclick(URL)
{
    警报(MyClick认证);
    如果(确认(你想激活该公司\\的主要公司和所有其他子公司?'))
        {
            location.href(URL);
        }};
< / SCRIPT>


解决方案

在您编辑的示例中的code失败,因为双重使用双引号的。

对于只显示确认与公司名称,如果 item.primary_company.HasValue 是真实的,这是可以做到无论是服务器端还是客户端。

服务器端,改怎么链接的作品取决于状态:

 <若%(item.primary_company.HasValue){%GT;
&所述; A HREF =#的onclick =返回Actionclick('&下;%= Url.Action(激活,新的{ID = item.company_id})%GT;','&下;%= Html.En code(item.company1.company_name)%GT;');
    类=FG =按钮FG-按钮图标独奏UI状态默认UI的角落都><跨度类=UI图标UI图标刷新>< / SPAN>< / A>
<%}其他{%GT;
&所述; A HREF =&下;%= Url.Action(激活,新的{ID = item.company_id})%>中
    类=FG =按钮FG-按钮图标独奏UI状态默认UI的角落都><跨度类=UI图标UI图标刷新>
        链路下; /跨度>&下; / A>
<%}%GT;<脚本类型=文/ JavaScript的>
    功能Actionclick(网址,公司名称){
        如果(确认(确认。公司名称='+的companyName)){
            location.href =网址;
        }
    };
< / SCRIPT>

客户端,发送一个参数的JavaScript,告诉它是否要确认:

 < A HREF =#的onclick =返回Actionclick('<%= Url.Action(激活,新{ID = item.company_id})%GT ;','<%= Html.En code(item.company1.company_name)%GT;',<%= item.primary_company.HasValue真:假%GT;)); 
    类=FG =按钮FG-按钮图标独奏UI状态默认UI的角落都><跨度类=UI图标UI图标刷新>< / SPAN>< / A><脚本类型=文/ JavaScript的>
    功能Actionclick(网址,公司名称,showConfirmation){
        如果(showConfirmation){
            如果(确认(确认。公司名称='+的companyName)){
                location.href =网址;
            }
        }
        其他{
            location.href =网址;
        }
    };
< / SCRIPT>

I have the following link. On click, I'd like to check the item.primary_company field and if populated, give the user a warning and ask if they would like to continue. How can I do this?

<a href="<%= Url.Action("Activate", new {id = item.company_id}) %>" class="fg=button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span></a>

EDIT

I've changed to this, but nothing happens when clicked. Also, I don't know how to reference the item to do the check on the primary_company field. I only want to message to show if item.primary_company.HasValue. I'd also like to show item.company1.company_name in the confirm message.

<a href="#" onclick="return Actionclick("<%= Url.Action("Activate", new {id = item.company_id}) %>");" class="fg=button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span></a>


<script type="text/javascript">
function Actionclick(url)
{
    alert("myclick");
    if ( confirm('Do you want to activate this company\'s primary company and all other subsidiaries?'))
        {
            location.href(url);
        }

};
</script>

解决方案

The code in your edited example fails because of the double use of doublequotes.

Regarding only showing the confirmation with the company name if item.primary_company.HasValue is true, it can be done either server side or client side.

Server side, change how the link works depending on the status:

<% if (item.primary_company.HasValue) { %>
<a href="#" onclick="return Actionclick('<%= Url.Action("Activate", new {id = item.company_id}) %>', '<%= Html.Encode(item.company1.company_name) %>');"
    class="fg=button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span></a>
<% } else { %>
<a href="<%= Url.Action("Activate", new {id = item.company_id}) %>"
    class="fg=button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh">
        link</span></a>
<% } %>

<script type="text/javascript">
    function Actionclick(url,companyName) {
        if (confirm('Confirm. CompanyName = ' + companyName)) {
            location.href = url;
        }
    };
</script>

Client side, send a parameter to javascript, telling it whether or not to confirm:

<a href="#" onclick="return Actionclick('<%= Url.Action("Activate", new {id = item.company_id}) %>', '<%= Html.Encode(item.company1.company_name) %>', <%= item.primary_company.HasValue ? "true" : "false" %>));"
    class="fg=button fg-button-icon-solo ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span></a>

<script type="text/javascript">
    function Actionclick(url,companyName,showConfirmation) {
        if (showConfirmation) {
            if (confirm('Confirm. CompanyName = ' + companyName)) {
                location.href = url;
            }
        }
        else {
            location.href = url;
        }
    };
</script>

这篇关于如何根据审定的ActionLink之前给用户的确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆