所以基本上我的模型中有一个布尔值,在我看来,我有一个隐藏字段,当我选择了某个选择框时,我将其设置为 true 或 false。现在我有了这个,我需要以某种方式检查隐藏字段的值和控制器中 bool 的值。如果是真的,我想运行一个方法,如果是假的,我希望它跳过该方法。
这是我的 html,不可见字段位于底部:
<div id="addTransfereeForm" class= "invisible" "whiteborder">
<form name="addTransferee" id="addTransferee">
<p><b><u>Add a New Transferee</u></b></p>
Transfer Effective Date: <input type="text" name="transfereffectivedate" class="datepicker"<br /> <br />
Transferee Name: <input type="text" name="transfereename" /><br />
Transferee Notice Address Line 1: <input type="text" name="transfereenoticeaddressline1" /><br />
Transferee Notice Address Line 2: <input type="text" name="transfereenoticeaddressline2" /><br />
Transferee Notice City: <input type="text" name="transfereenoticecity" /><br />
Transferee Notice State: <input type="text" name="transfernoticestate" /><br />
Transferee Notice Zip: <input type="text" name="tranfernoticezup" /><br />
Transferee Notice Phone: <input type="text" name="transfereenoticephone" /><br />
Transferee Payment Address Line 1: <input type="text" name="transfereepaymentaddressline1" /><br />
Transferee Payment Address Line 2: <input type="text" name="transfereepaymentaddressline2" /><br />
Transferee Payment City: <input type="text" name="transfereepaymentcity" /><br />
Transferee Payment State: <input type="text" name="transfereepaymentstate" /><br />
Transferee Payment Zip: <input type="text" name="transfereepaymentzip" /><br />
Transferee Payment Phone: <input type="text" name="transfereepaymentphone" /><br />
<input type="hidden" name="newtransferee" />
</form>
</div>
这是我的模型(NewTransferee 是我设置为真或假的布尔值):
public class CreateTransferee
{
public DateTime? TransferEffectiveDate { get; set; }
public string TransfereeName { get; set; }
public string TransfereeNoticeAddressLine1 { get; set; }
public string TransfereeNoticeAddressLine2 { get; set; }
public string TransfereeNoticeCity { get; set; }
public string TransfereeNoticeState { get; set; }
public string TransfereeNoticeZip { get; set; }
public string TransfereeNoticePhone { get; set; }
public string TransfereePaymentAddressLine1 { get; set; }
public string TransfereePaymentAddressLine2 { get; set; }
public string TransfereePaymentCity { get; set; }
public string TransfereePaymentState { get; set; }
public string TransfereePaymentZip { get; set; }
public string TransfereePaymentPhone { get; set; }
public bool NewTransferee { get; set; }
}
这是我的控制器(我需要编辑它以使其在运行结束部分之前检查布尔值):
[NoCache]
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult ResolveProfileSelectionRequired(ResolveProfileSelectionRequiredModel model)
{
var resolved = SqlDataProvider.ResolveProfileSelectionRequiredJobException(model);
return resolved ? Json("Success") : Json("Failed");
}
最后,如果 bool 为真(位于 SQLDataProvider.cs 中),我创建了要运行的方法:
public static int CreateNewTransferee(CreateTransferee model)
{
using (var db = new NJB.NJBDataContext())
{
var result = db.SP_AddTransferee(
model.TransferEffectiveDate,
model.TransfereeName,
model.TransfereeNoticeAddressLine1,
model.TransfereeNoticeAddressLine2,
model.TransfereeNoticeCity,
model.TransfereeNoticeState,
model.TransfereeNoticeZip,
model.TransfereeNoticePhone,
model.TransfereePaymentAddressLine1,
model.TransfereePaymentAddressLine2,
model.TransfereePaymentCity,
model.TransfereePaymentState,
model.TransfereePaymentZip,
model.TransfereePaymentPhone);
return (int) result.ReturnValue;
}
}