Эта форма используется для выбора услуг и товаров.Внутри этой формы у меня есть это текстовое поле поиска и кнопка, которую я хочу использовать с вызовом ajax для загрузки искомых данных, что очень хорошо работает с функцией поиска, но после завершения вызова ajax публикация формы также будет продолжена без нажатия кнопки.кнопка добавления, которая является кнопкой фактического действия, необходимой для отправки любых данных, выбранных внутри формы.Добавить кнопку необходимо, чтобы отправить эту форму.Текстовое поле поиска и действие кнопки выполняет процесс отправки формы без какого-либо согласия на событие.
My View Code
<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>
}
}
Текстовое поле поиска и кнопка Controller Action
[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);
}
}
Пожалуйста, мне нужна ваша помощь по этому странному вопросу.