現在、MVC asp.net を使用してオンライン申請フォームに取り組んでいます。
これが私のフォームです。
私が欲しいのは、ユーザーが個々のラジオボタンを選択したときに、他のラジオボタンのテキストフィールドを無効にする必要があるということです。JSFiddle hereを使用してこれを達成することができました。
私がしたことは
、1)作成したJSFiddleからのコーディングをMVCビューにコピーしたことです
@model Insurance.ViewModels.RegisterInfoPA
@{
ViewBag.Title = "Insert";
}
<h2>Insert Fire Insurance</h2>
<script>
$(".radioBtn").click(function () {
$("#reg_title").attr("disabled", true);
$("#reg_registerNm").attr("disabled", true); //Comp_Name//Name
$("#reg_identityNo").attr("disabled", true); //Ic_No//army//com_regis
$("#pinfo_gender").attr("disabled", true);
$("#busInfo_dateRegisCompany").attr("disabled", true);
$("#reg_dateCompRegis").attr("disabled", true); //DOB
$("#pinfo_occupation").attr("disabled", true);
$("#pinfo_maritalId").attr("disabled", true);
$("#busInfo_contactNm").attr("disabled", true);
$("#busInfo_natureBusiness").attr("disabled", true);
if ($("input[name=reg.identityId]:checked").val() == "1") {
$("#reg_title").attr("disabled", false);
$("#reg_identityNo").attr("disabled", false);
$("#pinfo_gender").attr("disabled", false);
$("#reg_dateCompRegis").attr("disabled", false);
$("#pinfo_maritalId").attr("disabled", false);
$("#pinfo_occupation").attr("disabled", false);
}
if ($("input[name=reg.identityId]:checked").val() == "2") {
$("#reg_registerNm").attr("disabled", false);
$("#busInfo_dateRegisCompany").attr("disabled", false);
$("#busInfo_natureBusiness").attr("disabled", false);
$("#busInfo_contactNm").attr("disabled", false);
}
});
</script>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<link href="~/Content/FlexiPA.css" rel="stylesheet" />
<fieldset>
<legend>register</legend>
<div class="flexiPAtitle">
<h3>
<b>
@Html.RadioButtonFor(model => model.reg.identityId, 1, new { @class = "radioBtn" })
Individual Applicant
@Html.RadioButtonFor(model => model.reg.identityId, 2, new { @class = "radioBtn" })
Company Application
@Html.HiddenFor(model=>model.reg.insuranceTypeId, 3)
</b>
</h3>
</div>
@Html.BeginForm() の前にコードを配置しました。しかし、それは機能していません。
2)そこで、コードを別のjsファイルに配置して、ビューから呼び出しようとしました
<h2>Insert Fire Insurance</h2>
<script src="~/Scripts/IndividualCompany.js"></script>
@using (Html.BeginForm())
{
まだ機能していません。私が間違っていたアイデア。このjqueryコードをMVCで使用する方法は、混乱します.JSFiddleでコードを実行したときはすべて問題ありませんが、MVCではそうではありません. また、nuget マネージャーから Jquery パッケージをインストールしました。本当にいくつかのガイダンスが必要です。
ありがとうございました。