これは私のhtmlです
<input type="text" name="name" id="name" />
<input type="text" name="age" id="age" />
<input type="button" id="button" value="Submit"/>
そして、以下はJSです
<script type="text/javascript">
$(document).ready(function () {
$("#button").click(function () {
var personalInfo = new Object();
personalInfo.name = $("#name").val();
personalInfo.age=$("#age").val();
$.ajax({
type: "GET",
url: "@Url.Action("SubmitForm","Account")",
data: 'myPersonalInfo='+personalInfo,
success: function () { alert("a"); }
});
});
});
</script>
そして、以下は私のコントローラーメソッドです
public ActionResult SubmitForm(string name,string age)
{
Session["Name"]=name;
Session["Age"]=age;
return View();
}
セッションを維持するには、ユーザー定義オブジェクト (PersonalInfo) をサーバーに送信し、その値を取得する必要があります。それはどのように行われるべきですか?助けてください