Hello,
I am new to ASP.NET MVC. I am trying to create what I thought was a basic functionality. I have a view that is accessed via "http://myserver.com/Products/Ship/". When a user visits this page, they will be prompted for the serial number of a product. After a user enters the serial number and clicks "next", I want to show them a drop down list of shipping options. I want to do this while keeping them at the "http://www.myserver.com/Products/Ship" url. Because of this, I thought JQuery would be a suitable answer. In the process, I have run into a problem. I cannot get to the second page as desired.
For reference, my view code looks like this:
<h2>Product Shipping</h2>
<p><form id="myForm" action="/Products/Ship" method="post">
<fieldset>
Product
<%= Html.TextBox("product", null, new{@class = "required product"}) %>
<br />
<input type="submit" value="OK" />
</fieldset>
</form></p>
<script type="text/javascript">
$(document).ready(function () {
$("#myForm").validate({ submitHandler: submitSerialNumber });
});
function submitSerialNumber () {
$post("/Products/Ship", "", function(result) { alert("woohoo 1"); });
}
</script>
My controller code looks like the following:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Ship()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult Ship(string serialNumber)
{
// Ensure that a serial number was entered
JsonResult result = null;
if (String.IsNullOrEmpty(serialNumber))
{
result = Json(new { success = false, message = "Please enter a serial number" });
return result;
}
// Obtain the list of options from the database. Hardcoded for testing
result = Json(new { success = true, message = "Option 1 | Option 2 | Option 3" });
return result;
}
Right now, when I run the page, FireFox prompts me to save the Json result when I submit a serial number. Am I way off here? It seems like I should be able to just flip the view via JavaScript. However, the posting is making it tricky. I need a way to get some results from the database when a user enters a serial number.
Thank you