Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net MVC 4 Ajax post request not working and I can't figure out why
    primarykey
    data
    text
    <p>I'm working on an ASP.net MVC 4 application, and in one of the pages I have a form that I am iterating through all the inputs and converting to json data.</p> <p>Using fiddler, chrome development tools, and firebug I have verified that the data is being converted to json correctly. I am using $ajax to post the data to an mvc controller and every time I do I get an error. </p> <p>I can't seem to figure out why it isn't working. I'm betting if I could figure out how to get the error message I could figure out how to get this working. When I try to view in the console I don't see the error message. I've tried logging to the console the error message but it doesn't show anything. </p> <p>If anyone can help me figure out how to get the error message I would appreciate it. I'm also posting the code in case I'm missing something glaringly obvious.</p> <p>Here is my javascript code:</p> <pre><code>$(function () { $("#saveform").submit(function () { var myRows = []; var $headers = $("th"); var $rows = $("tbody tr").each(function (i, n) { var $row = $(n); myRows.push({ id: $row.find('#item_SpecimenId').val(), site: $row.find('#item_Site').val(), clinicalImpression: $row.find('#item_ClinicalImpression').val(), degreeOfSuspicion: $row.find('#item_DegreeOfSuspicion').val(), margins: $row.find('#item_Margins :selected').text(), count: $row.find('#item_Count').val(), lesionSize: $row.find('#item_LesionSize').val(), }); }); var specimens = JSON.stringify(myRows); var url = '/PathSlip/DoctorSlip'; $.ajax({ url: url, data: '{ id:1, post:2 }', type: 'POST', dataType: 'json', statusCode: { 404: function () { $("#response").html('Could not contact server.'); }, 500: function () { $("#response").html('A server-side error has occurred.'); } }, success: function () { $("#response").html('success'); }, error: function (xhr, ajaxOptions, thrownError) { $("#response").html('an error'); } }); }); }); </code></pre> <p>Here is my viewModel for use in the controller</p> <pre><code>public class SpecimenViewModel { public int id { get; set; } public string site { get; set; } public string clinicalImpression { get; set; } public string degreeOfSuspicion { get; set; } public string margins { get; set; } public string count { get; set; } public string lesionSize { get; set; } } </code></pre> <p>Here is my mvc controller</p> <pre><code> public ActionResult DoctorSlip(int id) { var specimens = _repo.GetSpecimensByBiopsyId(id).ToList(); return View(specimens); } [HttpPost] public ActionResult DoctorSlip(IEnumerable&lt;SpecimenViewModel&gt; specimens) { return RedirectToAction("DoctorSlip"); } </code></pre> <p>Any help with this is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload