我有此表格用于选择服务和项目。在此表单中,我具有要使用的搜索文本框和按钮,它是ajax调用,用于加载搜索到的数据,搜索功能效果很好,但在ajax调用完成后,无需单击即可继续发布表单添加按钮,这是提交表单内选择的任何数据所需的实际操作按钮。添加按钮需要提交此表格。在没有任何事件同意的情况下,搜索文本框和按钮操作正在执行表单提交过程。
我的查看代码
<div id="serviceListArea" style="float: left; margin-left:10px; width:78%; height: 400px; overflow-y: auto;">
@{
var aOptions = new AjaxOptions()
{
Url = Url.Action("AddSelectedToOrder", "Hospital", new { PatientID = 64990, VisitID = 85499, PATIENT_TYPE = 2 }),
HttpMethod = "POST",
OnBegin = "OnAjaxRequestBegin('toBeOrderedServceListOnOrder','Adding selected service or item...')",
OnComplete = "OnAjaxRequestComplete()",
OnSuccess = "OnAjaxRequestComplete()",
OnFailure = "OnAjaxRequestFailure()",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "toBeOrderedServceListOnOrder"
};
using (Ajax.BeginForm(aOptions))
{
@Html.DevExpress().TextBox(
settings =>
{
settings.Name = "txtSelectedServiceTypeAndCategoryLinkHolder";
settings.Text = "";
settings.ClientVisible = false;
settings.Properties.EnableClientSideAPI = true;
settings.Enabled = true;
}).GetHtml()
@Html.DevExpress().TextBox(
settings =>
{
settings.Name = "txtServiceUIClassificationCategory";
settings.Text = "SERVICE";
settings.ClientVisible = false;
settings.Properties.EnableClientSideAPI = true;
settings.Enabled = true;
}).GetHtml()
<div id="serviceFilterArea">
@Html.DevExpress().FormLayout(
settings =>
{
settings.Name = "frmAddServiceList";
settings.SettingsAdaptivity.AdaptivityMode = FormLayoutAdaptivityMode.SingleColumnWindowLimit;
settings.Width = Unit.Percentage(100);
settings.ShowItemCaptionColon = true;
settings.Items.AddGroupItem(
groupSettings =>
{
groupSettings.Name = "groupFilterList";
groupSettings.Caption = "Service Filter";
groupSettings.ShowCaption = DefaultBoolean.False;
groupSettings.GroupBoxDecoration = GroupBoxDecoration.None;
groupSettings.ColCount = 4;
groupSettings.Items.Add(
item =>
{
item.Name = "lblServiceListSearch";
item.Caption = "Search Term";
item.ShowCaption = DefaultBoolean.False;
item.ColSpan = 2;
item.Width = Unit.Percentage(50);
item.NestedExtension().TextBox(
txtListSettings =>
{
txtListSettings.Name = "txtServiceListSearch";
txtListSettings.Properties.ClientSideEvents.KeyDown = "function(s,e) { OnServiceSearchKeyDown(s,e); }";
});
});
groupSettings.Items.Add(
item =>
{
item.Name = "lblSearchServiceList";
item.Caption = "Search Service List: ";
item.ShowCaption = DefaultBoolean.False;
item.NestedExtension().Button(
btnSettings =>
{
btnSettings.Name = "btnSearchServiceList";
btnSettings.Text = "Search";
btnSettings.ClientSideEvents.Click = "function(s,e) { OnServiceSearchButtonClick(s,e); }";
btnSettings.UseSubmitBehavior = false;
});
});
groupSettings.Items.Add(
item =>
{
item.Name = "lblAddServiceList";
item.Caption = "Add Service List: ";
item.ShowCaption = DefaultBoolean.False;
item.NestedExtension().Button(
btnSettings =>
{
btnSettings.Name = "btnAddServiceList";
btnSettings.Text = "Add";
btnSettings.EnableClientSideAPI = true;
btnSettings.UseSubmitBehavior = true;
});
});
});
}).GetHtml()
</div>
<div id="serviceListOnOrder">
</div>
}
}
搜索文本框和按钮“控制器操作”
[HttpGet]
[BriskActionFilter]
[BriskException]
public ActionResult LoadServiceOrItems()
{
string ServiceUIType = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceUIType", Request, RouteData);
long ServiceTypeID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("ServiceTypeID", Request, RouteData);
long ServiceCategoryID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("ServiceCategoryID", Request, RouteData);
string ServiceName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceName", Request, RouteData);
bool IsPharmacyService = BriskHelpers.Utility.UrlParameterParser<bool>.Parse("IsPharmacyService", Request, RouteData);
bool IsCertificate = BriskHelpers.Utility.UrlParameterParser<bool>.Parse("IsCertificate", Request, RouteData);
string ItemCode = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ItemCode", Request, RouteData);
string ItemName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ItemName", Request, RouteData);
if (IsPharmacyService)
{
if (!ViewData.ContainsKey("ItemName"))
ViewData.Add("ItemName", ItemName);
else
ViewData["ItemName"] = ItemName;
if (!ViewData.ContainsKey("IsPharmacyService"))
ViewData.Add("IsPharmacyService", IsPharmacyService);
else
ViewData["IsPharmacyService"] = IsPharmacyService;
Item[] items = IngeniousGlobal.IngInvMethod.GetItems(ItemCode, ItemName,-1, new string[] { "ITEM_FILTER_FOR_PRESCRIPTION" });
return PartialView("PharmacyItemListView", new List<Item>(items));
}
else if (IsCertificate)
{
ModuleServiceList[] certificateList = IngeniousGlobal.HospitalMethod.GetModuleServiceListInCategory(ServiceCategoryID, ServiceName);
return PartialView("CertificateListView", new List<ModuleServiceList>(certificateList));
}
else
{
ModuleServiceList[] servieList = IngeniousGlobal.HospitalMethod.GetModuleServiceListInCategory(ServiceCategoryID, ServiceName);
return PartialView("ServiceListView", new List<ModuleServiceList>(servieList));
}
}
搜索文本框和按钮JavaScript功能
function OnSearch(_sender) {
var txtServiceTypeUI = ASPxClientTextBox.Cast("txtServiceUIClassificationCategory");
var txtServiceTypeAndCategorySelected = ASPxClientTextBox.Cast("txtSelectedServiceTypeAndCategoryLinkHolder");
var _serviceUIType = txtServiceTypeUI.GetText();
var _containerName = "serviceListOnOrder";
var _url = txtServiceTypeAndCategorySelected.GetText();
var _searchKey = _sender.GetText();
var _message = "Please wait while service list loading ";
var _method = "GET";
if (_serviceUIType == "SERVICE") {
if (_url == "") {
_url = "/Hospital/LoadServiceOrItems?ServiceUIType=SERVICE&ServiceTypeID=-1&ServiceCategoryID=-1&ServiceName=" + _searchKey;
}
else {
_url = _url + "&ServiceName=" + _searchKey;
}
}
else if (_serviceUIType == "CERTIFICATE") {
_url = _url + "&ServiceName=" + _searchKey;
}
else if (_serviceUIType == "PHARMACY") {
_url = _url + "&ItemName=" + _searchKey;
}
OnAjaxRequest(_method, _url, _containerName, _message);
}
function OnServiceSearchKeyDown(_sender, _event) {
if (_event.htmlEvent.keyCode == 13) {
OnSearch(_sender);
}
}
function OnServiceSearchButtonClick(_sender, _event) {
var txtSearcKey = ASPxClientTextBox.Cast("txtServiceListSearch");
OnSearch(txtSearcKey);
}
使用上述javascript在搜索功能期间调用的意外控制器操作
[HttpPost]
[BriskActionFilter]
[BriskException]
public ActionResult AddSelectedToOrder()
{
long PatientID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("PatientID", Request, RouteData);
long VisitID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("VisitID", Request, RouteData);
PatientTypeList PATIENT_TYPE = (PatientTypeList)BriskHelpers.Utility.UrlParameterParser<int>.Parse("PATIENT_TYPE", Request, RouteData);
string url = Request["txtSelectedServiceTypeAndCategoryLinkHolder"];
string txtServiceUIClassificationCategory = Request["txtServiceUIClassificationCategory"];
string ServiceUIType = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceUIType", url);
long ServiceTypeID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("ServiceTypeID", url);
string ServiceTypeName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceType", url);
long ServiceCategoryID = BriskHelpers.Utility.UrlParameterParser<long>.Parse("ServiceCategoryID", url);
string ServiceCategoryName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceCategory", url);
string ServiceName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ServiceName", url);
bool IsPharmacyService = BriskHelpers.Utility.UrlParameterParser<bool>.Parse("IsPharmacyService", url);
bool IsCertificate = BriskHelpers.Utility.UrlParameterParser<bool>.Parse("IsCertificate", url);
string ItemCode = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ItemCode", url);
string ItemName = BriskHelpers.Utility.UrlParameterParser<string>.Parse("ItemName", url);
if (ViewData.ContainsKey("ServiceUIType"))
ViewData["ServiceUIType"] = ServiceUIType;
else
ViewData.Add("ServiceUIType", ServiceUIType);
if (ViewData.ContainsKey("PatientID"))
ViewData["PatientID"] = PatientID;
else
ViewData.Add("PatientID", PatientID);
if (ViewData.ContainsKey("VisitID"))
ViewData["VisitID"] = VisitID;
else
ViewData.Add("VisitID", VisitID);
if (ViewData.ContainsKey("PATIENT_TYPE"))
ViewData["PATIENT_TYPE"] = (int)PATIENT_TYPE;
else
ViewData.Add("PATIENT_TYPE", (int)PATIENT_TYPE);
if (IsPharmacyService)
{
return AddSelectedItems(url);
}
else if (IsCertificate)
{
return AddSelectedCertificate();
}
else
{
return AddSelectedService();
}
}
我的jQuery Ajax函数用于我的许多调用,并且效果很好
function OnAjaxRequestMain(_requestMethod, _url, _containerName, _message, _append, _contentType, _data, _dataType) {
try {
$.ajax({
type: _requestMethod,
url: _url,
data: _data,
dataType: _dataType,
contentType: _contentType,
beforeSend: function () {
OnAjaxRequestBegin(_containerName, _message);
},
success: function (response) {
var containerID = '#' + _containerName;
if (response.includes("ERROR")) {
OnAlert("erroralert", "errormsg", response);
}
else if (response.includes("WARNING")) {
OnAlert("warningalert", "warningmsg", response);
}
else if (response.includes("SUCCESS")) {
OnAlert("successalert", "successmsg", response);
}
else if (response.includes("INFO")) {
OnAlert("infoalert", "infomsg", response);
}
else {
if (_append)
$(containerID).html(response);
else
$(containerID).html(response);
}
OnAjaxRequestComplete();
},
error: function (request, status, error) {
var msg = "MSG: " + request.responseText + "<br />STATUS: " + status + "<br /> ERROR: " + error;
if (request.responseText.includes("ERROR")) {
OnAlert("erroralert", "errormsg", msg);
}
else if (request.responseText.includes("WARNING")) {
OnAlert("warningalert", "warningmsg", msg);
}
else if (request.responseText.includes("SUCCESS")) {
OnAlert("successalert", "successmsg", msg);
}
else if (request.responseText.includes("INFO")) {
OnAlert("infoalert", "infomsg", msg);
}
else {
OnAlert("erroralert", "errormsg", msg);
}
OnAjaxRequestFailure();
}
});
}
catch (ex) {
alert("Error: Brisk On AjaxRequest Main" + ex.message);
}
}
在这个奇怪的问题上,请您帮忙。