简体   繁体   English

我们可以将 JavaScript 代码沿 c# 放入.NetCore WebApi

[英]Can we place JavaScript Code along c# in .NetCore WebApi

I have a method in my asp.net Core web Api that has for role sending Emails, using SmtpClient .我的 asp.net Core web Api 中有一个方法,该方法具有使用SmtpClient发送电子邮件的作用。 the Body of the message is this html string:消息的正文是这个 html 字符串:

  @"<html>
         <head>
              <style>
                   #modalHeader{
                        background-color:#6495ED;
                        color:white;
                        text-align: center;
                        height:80px;
                       }  
                        .example_b {
                                      color: #fff !important;
                                      text-transform: uppercase;
                                      text-decoration: none;
                                      background: #60a3bc;
                                      padding: 20px;
                                      border-radius: 50px;
                                      display: inline-block;
                                      border: none;
                                      transition: all 0.4s ease 0s;
                                     }
                                    .example_b:hover {
                                            text-shadow: 0px 0px 6px rgba(255, 255, 255, 1);
                                            -webkit-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
                                            -moz-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
                                            transition: all 0.4s ease 0s;
                                            }
                                </style>
                            </head>
                      <body>
                        <p>Bonjour,<br> 
                            Afin d’authentifier votre connexion sur le système de prise de rendez-vous à distance de la " + Structure + @" Nous vous invitons à  confirmer votre mail en cliquant sur ce lien 
                         </p>
                    <div style='border:1px solid black'>
                          //<div id='modalHeader'>Confirmation d'Email</div>
                            //<br>
                                //<br>
                            <div id='modalBody'>
                              <div class='button_cont' align='center'>
                                <a class='example_b' href='" + url + "' target='_blank' rel='nofollow noopener'>Confirmer Votre Email</a>" +
                                "</div> </div> <br/> </div> </body> </html>";

as you see im using a href to trigger a call to another method in service, the problem with that is that it opens to me a blank page each time i click the button, so the solution would be to add an event instead to the button using javascript.如您所见,我使用href触发对服务中的另一种方法的调用,问题在于每次单击按钮时它都会向我打开一个空白页面,因此解决方案是将事件添加到按钮使用 javascript。

My question is how can i add Js to c# code in asp.net core 2.1?我的问题是如何将 Js 添加到 asp.net 核心 2.1 中的 c# 代码中? is adding just script tag inside the html tag would make the work of letting JS doing the work?html 标记中添加脚本标记是否可以让 JS 完成工作?

You can't execute javascript inside an email.您不能在 email 中执行 javascript。 This used to be possible in the 90's and early 2000's, but it is no longer possible.这在 90 年代和 2000 年代初期曾经是可能的,但现在已经不可能了。

If you inspect the element in the email are you sure you see the correct url?如果您检查 email 中的元素,您确定看到正确的 url 吗? If yes maybe it would be worth giving a try to inspect an href link in one email.如果是,也许值得尝试检查一个 email 中的 href 链接。 I checked at the moment and I saw something like that:我当时检查了一下,我看到了类似的东西: 在此处输入图像描述 It could be worth the try...可能值得一试...

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

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