Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to fetch the data from my mvc application I am using FormCollection class. when I use httpget with this class then I show me page but when I use httppost and arun this application then it show me this error

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /

Here is my code

[HttpPost]
        public ActionResult Create(FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                foreach (string key in formCollection.AllKeys)
                {
                    Response.Write("Key=" + key + " ");
                    Response.Write("Value=" + formCollection[key]);
                    Response.Write("<br/>");
                }
            }

            return View();
        }

Its My view

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Employee</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Gender)
        </div>
        <div class="editor-field">
          @*  @Html.EditorFor(model => model.Gender)*@


           @Html.DropDownList("Gender", new List<SelectListItem>
            {
            new SelectListItem { Text = "Male", Value="Male" },
            new SelectListItem { Text = "Female", Value="Female" }
            }, "Select Gender")

            @Html.ValidationMessageFor(model => model.Gender)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateOfBirth)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateOfBirth)
            @Html.ValidationMessageFor(model => model.DateOfBirth)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

Please tell me where I am wrong

share|improve this question
1  
You need two actions: one that handles the GET and displays the form to the user and then a second that handles the POST when the user submits the form. –  jmcilhinney 11 hours ago
 
thanks @jmcilhinney its work but tell me one thing here why we need to add httppost and httpget in this process?? –  Azad Chouhan 11 hours ago
 
That attribute specifies that the action can only be invoked on a GET or POST. It's not so important that you use HttpGet but it is important that you use HttpPost because you don't want people to be able to directly invoke an action that is intended to be used for form submission. –  jmcilhinney 6 hours ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.