按钮更改值然后使用MVC&提交使用Javascript [英] Button to change a value then submit using MVC & Javascript
问题描述
嗨大家。
我有一个MVC表单,用户可以选择普通保存(使用提交)或保存并返回表单保存的位置和他们继续。
为了达到这个目的,我想在单击第二个按钮时触发一些jscript,它将模型中的值设置为true,然后我想要它然后提交。
我试过以下
Hi Guys.
I have an MVC form where the user has the option to plain Save (using submit) or save and return where the form saves and they move on.
To achieve this I want to fire some jscript when the second button is clicked, it sets a value in the model to true, then I want it to then submit.
I tried the following
<input type="submit" value="Save & Return to Menu" name="SaveAndReturn" id="SaveAndReturn" />
带
With
$("#SaveAndReturn").click(function () {
$("#ReturnToList").val(true);
});
但是这只是提交,因为jscript并没有因为首先提交而被解雇。
我的MVC表格开头以下我相信按钮应如下所示:
But this simply submits presumably because the jscript doesn''t get fired as the submit occurs first.
My MVC form starts with the following and I believe the button should be like the following:
@using (Html.BeginForm("HelpdeskView", "Helpdesk", @Model))
{
<input type="button" value="Save & Return to Menu" name="SaveAndReturn" id="SaveAndReturn" />
}
但是我不知道该怎么做jscript。(我是新来的......)
我试过了:
But I don''t know what to do about jscript. (I''m new to this...)
I have tried:
$("#SaveAndReturn").click(function () {
$("#ReturnToList").val(true);
document.getElementById("HelpdeskView").submit();
});
但这不起作用。
请帮忙......我很确定这很容易,但我很难......
谢谢
But this doesn''t work.
Please help... I''m sure it''s easy, but I''m struggling...
Thanks
推荐答案
(#SaveAndReturn)。click(function(){
("#SaveAndReturn").click(function () {
(#ReturnToList)。val(true);
});
("#ReturnToList").val(true); });
但这只是提交,因为jscript在提交首先发生时不会被解雇。
我的MVC表单从以下开始,我相信按钮应如下所示:
But this simply submits presumably because the jscript doesn''t get fired as the submit occurs first.
My MVC form starts with the following and I believe the button should be like the following:
@using (Html.BeginForm("HelpdeskView", "Helpdesk", @Model))
{
<input type="button" value="Save & Return to Menu" name="SaveAndReturn" id="SaveAndReturn" />
}
但是我不知道该怎么做jscript。(我是新来的......)
我试过了:
But I don''t know what to do about jscript. (I''m new to this...)
I have tried:
(#SaveAndReturn)。click(function(){
("#SaveAndReturn").click(function () {
这篇关于按钮更改值然后使用MVC&提交使用Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!