伙计们。
我对我的 ASP.NET MVC 项目有一个看法。这个视图有很多字段和一个脚本来搜索一些数据。
<link href="@Url.Content("~/Content/styles/people.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/people.js")" type="text/javascript"></script>
<input type="hidden" id="selectiveAccess" name="selectiveAccess" value="@ViewBag.SelectiveAccess" />
<input type="hidden" id="peopleID" name="peopleID" value="@ViewBag.PeopleID" />
<div id="content">
<h1>People - Create</h1>
<h3>All the fields with (*) are required.</h3>
@using (Html.BeginForm("Save", "People", FormMethod.Post))
{
@Html.Partial("EnabledCourses")
@Html.Partial("GeneralData")
@Html.Partial("AddressData")
@Html.Partial("ContactData")
@Html.Partial("OtherInformations")
@Html.Partial("Research")
<a href="#top">Back to the top</a>
<div id="divErrors"></div>
<div id="actions">
<ul style="list-style: none;">
<li style="display: inline"><input type="reset" id="clear" style="height: 3em; width: 10em" value="Clear form" /></li>
<li style="display: inline"><input type="submit" id="continue" style="height: 3em; width: 10em" value="Continue" /></li>
</ul>
</div>
}
当我调用 Index() 时,脚本运行良好。
public ActionResult Index()
{
ViewBag.PeopleID = string.Empty;
return View();
}
当我调用 Edit() 时,相同的脚本不起作用。
public ActionResult Edit(long peopleID)
{
ViewBag.PeopleID = peopleID;
return View("Index");
}
这是脚本:
function searchCityByPostalCode() {
var postalCode = {
'postalCode': $('#postalCode').val()
};
$.get(
'people/SearchCityByPostalCode',
postalCode,
function (city) {
// do something that works.
}
);
}
有谁知道这个问题?谢谢!!!