mvc html 按钮事件,.net c#单击按钮不会触发事件-MVC Razor

I have gone through previous posts on the same topic but I couldn't figure out what's wrong with my code. Here's my html

@model Models.Submissions

@{

ViewBag.Title = "Application";

}

@ViewBag.Title

@using (Html.BeginForm("Create","Submissions",FormMethod.Post))

{

@Html.ValidationSummary(true)

@Html.LabelFor(model => model.SubmissionId)

@Html.TextBoxFor(model => model.SubmissionId)

@Html.LabelFor(model => model.SubmissionDate)

@Html.TextBoxFor(model => model.SubmissionId)

}

@Html.ActionLink("Back to List", "Index")

@section Scripts {

@Scripts.Render("~/bundles/jqueryval")

}

Here's my controller. The button click doesn't trigger the http post method of the submissions controller . By the way, my controller is "SubmissionsController"

public ActionResult Create()

{

return View();

}

[HttpPost]

public ActionResult Create(Submissions submission)

{

try

{

// TODO: Add insert logic here

// my logic

return RedirectToAction("Index");

}

catch

{

return View();

}

}

}

Thanks..! Help Appreciated

Talk1:

Your code looks OK. Are you sure your controller is not being hit? Have you put a breakpoint on the first line to check?

Talk2:

I think you're wanting SubmissionDate in your second textbox. Can you show the view model?

Talk3:

@Html.ValidationSummary(true) means to display only errors not directly associated with a property (which means you also need to include @Html.ValidationMessageFor() for each property), otherwise use @Html.ValidationSummary(false)

Talk4:

Thanks StephenMuecke and Jonesy for your valuable inputs. The problem was due the @scripts.render part in my code that was causing client side validation. I have disabled it and and now it is working fine.

Solutions1

Seems you're trying to include jquery validation for the form as well, so my humble guess would be, that your client-side validation prevents postback to the server due to a validation error. Try to disable that validation and try again. Can't provide more info, because I don't know what exactly does your javascript do, but I think you should be able to fix it yourself now.

And as Jonesy correctly pointed out, you have a typo in your code. The second textbox should be model.SubmissionDate. That is probably causing the validation error I've mentioned earlier.

Talk1:

I think this along with Stephen's comment should set him straight

Talk2:

I was able to fix the issue. Thanks a bunch walther.

Talk3:

, no problem. If I was right, you should probably mark my answer as accepted, so that other people see how you fixed it for future reference...

Talk4:

Apologies ... Done :) new to Stack overflow and MVC too .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值