ASP MVC Bootstrap项目 - 激活电子邮件按钮

时间:2015-11-19 10:23:21

标签: asp.net asp.net-mvc twitter-bootstrap email

我刚刚在一个空的ASP MVC项目中实现了一个bootstrap-theme。在引导程序中有一个电子邮件表单。我想激活“发送”按钮并让它发送电子邮件给我。当我读到它时,我已经看到了不同类型的解决方案:

只需使用:

<a href="mailto:EMAILADDRESS"> 

form method="post" action="mailto:youremail@youremail.com" >
<input type="submit" value="Send Email" /> 
</form>

或者更复杂的方式,使用jQuery并在模型和控制器中编写东西。

所以我的问题是:为什么我应该使用(对我来说)更复杂的方式?

以下是bootstrap附带的代码:

<!-- Contact Section -->
@*<section id="contact">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2>Contact Me</h2>
                <hr class="star-primary">
            </div>
        </div>
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2">
                <!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
                <!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
                <form name="sentMessage" id="contactForm" novalidate>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Name</label>
                            <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Email Address</label>
                            <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Phone Number</label>
                            <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Message</label>
                            <textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <br>
                    <div id="success"></div>
                    <div class="row">
                        <div class="form-group col-xs-12">
                            <button type="submit" class="btn btn-success btn-lg">Send</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>*@
<!-- Footer -->

1 个答案:

答案 0 :(得分:1)

假设您计划在将来为您的电子邮件发送应用添加更多内容,您应该更喜欢看似复杂的方式,因为从长远来看,它实际上会使事情变得更简单。这种复杂的方式基于一个名为“Separation of Concerns”的概念。

简而言之,如果想要一个向您发送电子邮件的按钮,则将代码分解为模型和控制器会更复杂。但随着您的程序越来越复杂并且您向其中添加更多内容,此技术将使您可以更轻松地重用或更新程序的特定方面。