0

I am new to MVC and is using MVc4 with VS2013. This is my controller:

 [HttpPost]
 public ActionResult Create(CreateRequestViewModel viewModel)
 {
    if (ModelState.IsValid)
    {
        return RedirectToAction("Index");
    }             
    return View(viewModel);
}

Below is my view:

@model ProMs.Web.ViewModels.CreateRequestViewModel

@{
    ViewBag.Title = "Create";
}

<body>

    <h2>New Request</h2>
    <h3></h3>
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <fieldset>

            <div class="float-left">
                <label for="RequestName">Request</label>
                @Html.EditorFor(model => model.Request.RequestName)
                @Html.ValidationMessageFor(model => model.Request.RequestName)

                @Html.LabelFor(model => model.Request.Requestor)
                @Html.EditorFor(model => model.Request.Requestor)
                @Html.ValidationMessageFor(model => model.Request.Requestor)

                @Html.LabelFor(model => model.Request.Purpose)
                @Html.EditorFor(model => model.Request.Purpose)
                @Html.ValidationMessageFor(model => model.Request.Purpose)
            </div>

            <div class="float-right">
                @Html.LabelFor(model => model.Request.Investigator)
                @Html.EditorFor(model => model.Request.Investigator)
                @Html.ValidationMessageFor(model => model.Request.Investigator)

                @Html.LabelFor(model => model.Request.Department)
                @Html.EditorFor(model => model.Request.Department)
                @Html.ValidationMessageFor(model => model.Request.Stage)

                @Html.LabelFor(model => model.Request.Comment)
                @Html.EditorFor(model => model.Request.Comment)
                @Html.ValidationMessageFor(model => model.Request.Comment)                
            </div>

            @Html.HiddenFor(model => model.Request.RequestID)
            @Html.HiddenFor(model => model.Request.DateCreated)
            @Html.HiddenFor(model => model.Request.CreatedBy)               

        </fieldset>
    }

     <p>
         <input type="submit" value="Submit" />
     </p>

</body>

Nothing happened if "submit" button is clicked. I even cold not put a breaking point at the line .

Thanks very much for your help.

Hugh

2
  • Hi Brand, Thanks very much for your help. It was my careless mistake. BTW, I could bot "Vote" your answer. Nothing happened after I clicking the "vote" tab. Hugh Commented Feb 3, 2014 at 17:34
  • No problem. Did you try clicking the checkmark underneath the arrows? That will accept the answer as the solution to your question. Commented Feb 3, 2014 at 18:00

1 Answer 1

2

@Html.BeginForm() creates a <form> element. Right now your submit button is outside of this element, so move it inside.

}

 <p>
     <input type="submit" value="Submit" />
 </p>

Should be

 <p>
     <input type="submit" value="Submit" />
 </p>

} <-- This goes down here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.