【发布时间】:2018-09-03 11:49:59
【问题描述】:
我现在用jQuery-Steps lib 以简单的形式创建了向导。没有提交按钮。我通过 jQuery 在完成步骤提交表单。
我已经在到处使用 jQuery 调用,并且我已经包含了所有脚本,并且我需要用于上传图像和其他内容的表单,使用它更容易。
什么都没有发生,控制器动作没有被调用。
我刚刚在开始页面上使用查询字符串中的所有这些参数进行了重定向。
像这样:
https://localhost:44380/Dashboard?Name=Aaaa&Surename=Bbbb&City=Cccc
仪表板全部由 Ajax 和局部视图组成。并且从菜单中的人员选项中,我将使用所有这些参数在仪表板的主页视图中重定向。
这是表格:
<form asp-controller="PersonSettings" asp-action="SaveForm" data-ajax="true" data-ajax-method="POST" id="personForm" class="steps-validation wizard-notification">
<!-- Step 1 -->
<h6>Person</h6>
<fieldset>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="Name">
Person Name :
<span class="danger">*</span>
</label>
<input autocomplete="off" type="text" class="form-control required" id="Name" name="Name">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="Surname">
Person Surname:
<span class="danger">*</span>
</label>
<input autocomplete="off" type="url" class="form-control required" id="Surname" name="Surname">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="City">
Person City:
<span class="danger">*</span>
</label>
<input autocomplete="off" type="url" class="form-control required" id="City" name="City">
</div>
</div>
</div>
</fieldset>
</form>
这是模型:
public class PersonDto {
public string Name { get; set; }
public string Surname { get; set; }
public string City { get; set; }
}
这是 PersonSettings 控制器中的操作:
[Route("SaveForm")]
[HttpPost]
public IActionResult SaveForm(PersonDto Person) {
//Do something with person model
return Ok();
}
在完成按钮上,我在此表单上调用了 jQuery 提交:
$('#personForm').submit();
编辑:
我尝试了这个参数:
<form action="PersonSettings/SaveForm" method="post" id="personFrom" class="steps-validation wizard-notification">
这行得通..很好,但是为什么第一种方法行不通?因为我在 Ajax 和完成方法中需要这个。
我没有找到任何使用经典 Ajax 调用的形式发布图像的方法。因为我无法读取图像路径(它不会暴露给浏览器)。
【问题讨论】:
-
Nothing happens, Controller Action is not called:是否正在拨打电话,如果是;服务器的响应是什么? (可以是 400、404、500 等) -
检查我编辑的答案。我没有看到 Action 被调用。我检查了网络选项卡,只有活动(除了加载页面等)是带有参数的 /Dashboard 的活动。我的仪表板控制器与我使用表单调用的不同。
标签: c# asp.net-mvc asp.net-core