@ Url.Action results 404 error when calling from the form

advertisements

I work on ASP.NET MVC application. Table is being populated using jQuery, but it doesn't matter now.

The problem is this: When I make a call with form tags, I get an error 404 Not Found. By inspecting I confirmed that model is bound OK (it's populated).

When I comment out form tags, I can make a call to method, but with model being null (like it's not bound).

Here is some of code I use:

@model  PayrollModel

@*@using (Html.BeginForm("Index", "Request", FormMethod.Post, new { id = "frmPersonView" }))
{*@

    <table data-dataurl="@Url.Action("PayrollData", "Payroll")" id="tblData" class="table hover table-bordered table-striped"></table>
@*}*@

Here is my controller method:

[HttpGet]
public ActionResult PayrollData(PayrollModel model)
{
    //do something
}

Edited: I found out why this happens: Request URL:

http:// localhost/CT.ISVDV.WebUI/Payroll/PayrollData?sEcho=1&iColumns=5&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=FIRSTNAME&mDataProp_1=LASTNAME&mDataProp_2=RIGHTGROUPNAME&mDataProp_3=DISABILITYTYPENAME&mDataProp_4=AMOUNT&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&SelectedTypes%5B3%5D=4&SelectedTypes%5B4%5D=5&SelectedTypes%5B5%5D=6&SelectedTypes%5B6%5D=7&SelectedTypes%5B7%5D=8&SelectedTypes%5B8%5D=9&SelectedTypes%5B9%5D=10&SelectedTypes%5B10%5D=11&SelectedTypes%5B11%5D=12&SelectedTypes%5B12%5D=13&SelectedTypes%5B13%5D=14&SelectedTypes%5B14%5D=15&SelectedTypes%5B15%5D=16&SelectedTypes%5B16%5D=17&SelectedTypes%5B17%5D=18&SelectedTypes%5B18%5D=19&SelectedTypes%5B19%5D=20&SelectedTypes%5B20%5D=21&SelectedTypes%5B21%5D=22&SelectedTypes%5B22%5D=23&SelectedTypes%5B23%5D=24&SelectedTypes%5B24%5D=25&SelectedTypes%5B25%5D=26&PayrollDate=01.12.2014&PayrollSearch.RIGHTGROUPIDList.Value%5B0%5D=4&PayrollSearch.RIGHTGROUPIDList.Value%5B1%5D=5&PayrollSearch.RIGHTGROUPIDList.Value%5B2%5D=6&PayrollSearch.RIGHTGROUPIDList.Value%5B3%5D=7&PayrollSearch.RIGHTGROUPIDList.Value%5B4%5D=8&PayrollSearch.RIGHTGROUPIDList.Value%5B5%5D=9&PayrollSearch.RIGHTGROUPIDList.Value%5B6%5D=10&PayrollSearch.RIGHTGROUPIDList.Value%5B7%5D=11&PayrollSearch.RIGHTGROUPIDList.Value%5B8%5D=12&PayrollSearch.RIGHTGROUPIDList.Value%5B9%5D=13&PayrollSearch.RIGHTGROUPIDList.Value%5B10%5D=14&PayrollSearch.RIGHTGROUPIDList.Value%5B11%5D=15&PayrollSearch.RIGHTGROUPIDList.Value%5B12%5D=16&PayrollSearch.RIGHTGROUPIDList.Value%5B13%5D=17&PayrollSearch.RIGHTGROUPIDList.Value%5B14%5D=18&PayrollSearch.RIGHTGROUPIDList.Value%5B15%5D=19&PayrollSearch.RIGHTGROUPIDList.Value%5B16%5D=20&PayrollSearch.RIGHTGROUPIDList.Value%5B17%5D=21&PayrollSearch.RIGHTGROUPIDList.Value%5B18%5D=22&PayrollSearch.RIGHTGROUPIDList.Value%5B19%5D=23&PayrollSearch.RIGHTGROUPIDList.Value%5B20%5D=24&PayrollSearch.RIGHTGROUPIDList.Value%5B21%5D=25&PayrollSearch.RIGHTGROUPIDList.Value%5B22%5D=26&tblData_length=10&

Up to this point, everything is right, but then i also passes some strange values that are not model properties. This happens only if I use form tags, and I need those.

DXScript=1_157%2C1_89%2C1_88%2C17_28%2C17_2%2C1_149%2C1_86%2C1_141%2C1_96%2C17_7%2C1_139%2C1_98%2C1_97%2C17_8%2C1_155%2C1_125%2C1_156%2C1_118%2C17_9%2C1_148%2C1_147%2C1_132%2C17_27%2C1_142%2C1_93%2C1_119%2C1_99%2C1_151%2C1_126%2C17_13%2C1_108%2C1_115%2C1_137%2C1_92%2C1_152%2C1_128%2C17_15%2C1_129%2C1_120%2C17_11%2C1_131%2C1_140%2C1_134%2C17_18%2C1_145%2C17_20%2C1_143%2C1_138%2C1_146%2C1_150%2C17_23%2C17_26%2C1_95%2C5_5%2C5_4%2C4_11%2C4_10%2C4_6%2C4_7%2C4_9%2C17_14%2C4_12%2C1_107%2C1_110%2C4_13%2C4_14%2C1_106%2C1_124%2C17_12%2C1_144%2C7_48%2C1_91%2C7_50%2C17_19%2C1_100%2C1_103%2C1_111%2C17_0%2C1_114%2C1_101%2C17_1%2C1_102%2C17_3%2C1_104%2C1_116%2C17_5%2C1_130%2C1_113%2C17_16%2C17_17%2C1_112%2C17_24%2C1_117%2C10_2%2C10_1%2C10_3%2C10_4%2C17_4%2C9_15%2C9_12%2C9_10%2C17_21%2C9_14%2C9_11%2C9_13%2C8_10%2C8_17%2C8_24%2C8_26%2C8_9%2C8_12%2C8_13%2C8_18%2C17_22%2C8_21%2C8_23%2C8_22%2C8_16%2C8_19%2C8_20%2C8_14%2C8_15%2C8_25%2C8_11%2C6_12%2C17_25&DXCss=%2FCT.ISVDV.WebUI%2Fimg%2Ffavicon.ico%2C%2FCT.ISVDV.WebUI%2FContent%2Fjvectormap%2Fjquery-jvectormap-1.2.2.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fbootstrap.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2Ffont-awesome.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fionicons.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2FiCheck%2Fall.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fcolorpicker%2Fbootstrap-colorpicker.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2Ftimepicker%2Fbootstrap-timepicker.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fmorris%2Fmorris.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fdatepicker%2Fdatepicker3.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fdaterangepicker%2Fdaterangepicker-bs3.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fbootstrap-wysihtml5%2Fbootstrap3-wysihtml5.min.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fcss%2Fselect2.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fselect2-bootstrap.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fdatatables%2FdataTables.bootstrap.css%2C%2FCT.ISVDV.WebUI%2FContent%2FAdminLTE.css%2C%2FCT.ISVDV.WebUI%2FContent%2FSite.css%2C%2FCT.ISVDV.WebUI%2FContent%2Fjquery.bootstrap-touchspin%2Fjquery.bootstrap-touchspin.css%2C1_9%2C1_11%2C0_844%2C0_842%2C1_8%2C0_691%2C0_694%2C0_682%2C1_4%2C0_684%2C0_805%2C0_698%2C4_2%2C0_700%2C5_1%2C0_782%2C0_762%2C0_764%2C7_1%2C7_0%2C1_1%2C0_657%2C0_869%2C0_871%2C0_777%2C8_2%2C0_779%2C8_0%2C0_794%2C6_2%2C0_796&_=1417596051723

How can I prevent this from happening?


Your formatting is off. Try mix single quotes with double ones:

data-dataurl='@Url.Action("PayrollData", "Payroll")'

PayrollData expects a PayrollModel model and you're providing none. There's no reasonable way to send a whole model using Url.Action so consider sending only an ID.

data-dataurl='@Url.Action("PayrollData", "Payroll", new { id = model.ID })'