weixin_33681778 2018-12-17 18:51 采纳率: 0%
浏览 27

Ajax请求关闭MVC表单

I am trying to do an ajax request and depending on the ajax request results I will allow the form to submit to the controller. However everytime the ajax request runs I get the error message.

Here is my javascript function:

function CheckForValidation(e) {
    var scholarshipRequest = $("#scholars").val();
    var aidYearRequest = $("#aidYear").val();
    var amountRequest = $("#amount").val();

    $.ajax({
        type: "POST",
        url: '@Url.Action("Validate_ScholarshipRequest", "RequestController")',
        data: {
            scholarshipId: scholarshipRequest,
            aidYear: aidYearRequest, 
            amount: amountRequest
        }
    }).success(function(response) {
        if (!response.success) {
            e.preventDefault();
            alert(success);
        } else {
            e.preventDefault();
        }
    }).error(function() {
        e.preventDefault();
        alert("Error on Submission");
    });
}

This function is called from here:

$("#SubmitTutorRequestFrm").submit(function(e) {
    e.PreventDefault();
    CheckForValidation(e);
});

I try to debug the code and put a breakpoint on Validate_ScholarshipRequest but that method never gets called. The method signature is:

public ActionResult Validate_ScholarshipRequest(string scholarshipId, string aidYear, string amount)

This is the start of my form:

@using (Html.BeginForm("SubmitScholarshipRequest", "Request", FormMethod.Post, new { id = "SubmitTutorRequestFrm" }))
  • 写回答

1条回答 默认 最新

  • perhaps? 2018-12-18 08:04
    关注

    Just to get this officially answered and "closed", this was caused by a syntax-error:

    url: '@Url.Action("Validate_ScholarshipRequest", "RequestController")',
    

    Controller should not be included in the controller name. The correct action would then be:

    url: '@Url.Action("Validate_ScholarshipRequest", "Request")',
    
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示