Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:21:53+00:00 2026-05-18T07:21:53+00:00

I am trying out ASP.Net MVC2 by building a small sample website which, amongst

  • 0

I am trying out ASP.Net MVC2 by building a small sample website which, amongst other features provides the user with a ‘Contact Us’ page. The idea is to allow a user to enter their name, email address, message subject and message. To send the message the user clicks on an ActionLink. This is the view:

    <% Html.BeginForm(); %>
<div>
    <%: Html.Label("Name")%>
    <br />
    <%: Html.TextBox("txtName", "",new { style = "width:100%" })%>
    <br />
    <%: Html.Label("Email address")%>
    <br />
    <%: Html.TextBox("txtEmail", "", new { style = "width:100%" })%>
    <br />
    <%: Html.Label("Subject")%>
    <br />
    <%: Html.TextBox("txtSubject", "", new { style = "width:100%" })%>
    <br />
    <%: Html.Label("Message")%>
    <br />
    <%: Html.TextBox("txtMessage", "", new { style = "width:100%" })%>
</div>
<div style='text-align: right;'>
    <%: 
        Html.ActionLink("Send", "SentEmail", new { name = Html.g, sender = "txtEmail", subject = "txtSubject", message="txtMessage" })
    %>      
</div>
<% Html.EndForm(); %>

The idea is once the ActionLink has been clicked a method in the controller is called into which the username, email address, subject and message will be passed. This is the method in the controller:

        public ActionResult SentEmail(string name, string sender, string subject, string message)
    {
        //Send email here and then display message contents to user.
        ViewData["Name"] = name;
        ViewData["Message"] = message;
        ViewData["ThankyouMessage"] = "Thank you for contacting us. We will be in touch as soon as possible.";
        return View();
    }

However… when I click the link the values which are passed into the method are null. I have tried creating a route to do this but it doesn’t work either. Should I be using another method?

Thank you,

Morris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:21:54+00:00Added an answer on May 18, 2026 at 7:21 am

    The action link isn’t going to trigger a http post nor will it pass in the values of your form fields, just a http get and not passing through any form data – ideally you’d use an input submit button to post the data. What is certain is that it is good practise that any request that causes creating/updating of data should be done via a http post.

    Submit button would just be like.

    <input type="submit" value="Send" />
    

    You then have several ways of accessing the form data firstly you could use a FormCollection to access the data

    [HttpPost]
    public ActionResult SendEmail(FormCollection collection)
    {
        string email = collection["txtEmail"];
        ...
    }
    

    Secondly you could use the method parameters and rely on model binding, but you must make sure field names match the parameter name so

    <%: Html.TextBox("txtEmail", "", new { style = "width:100%" })%>
    

    …would require…

    [HttpPost]
    public ActionResult SendEmail(string txtEmail)
    {
        ...
    }
    

    If this form isn’t being posted to the same action thats return the view then you’d also need to change your begin form tag, ideal you should use ‘using’ with it as well. So you’d get:

    <% using (Html.BeginForm("SendEmail", "<controller-name>"))
       { %>
    .... form fields in here ...
    <input type="submit" value="Send" />
    <% } %>
    

    If the button isn’t suitable for your design you could use something like:

    <input type="image" src="<%: Url.Content("~/Content/images/myimage.gif") %>" value="Send" />
    

    This would have the same effect. To trigger a post from an a tag though you’d need to look at using javascript, I can’t remember the exact syntax but off hand I think if you used jquery you’d be looking at something like: (form a single form page only)

    <a href="#" click="$('form').submit(); return false;">Send</a>
    

    But then you create a dependency on javascript where as really you should try have your site degrade gracefully so it can be used by visitors with javascript disabled. There are perhaps more advanced way of achieving this whilst meeting design requirements but that can get heavily into client side code which is probably outside of what you want for your sample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.