我这里有这段代码并且警报('test')被击中但由于某种原因.ajax 没有。 IT 不会给我任何错误,也不会向控制器传递任何信息。我以前做过 100 次,从来没有遇到过这个问题。有什么理由吗?谢谢所有的变量都有值等等。
尝试将 url 设为 url: '@Url.Action("Add_ICLog_LogEntryRecommendation_Submit", "References")',
<div class="card-block" id="RecommendationTypeAddModal">
@*@using (Ajax.BeginForm("Log/Investment/Committee/Recommendation/Add/Submit", "References", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "ICLogRecommendationTypeAddForm",
HttpMethod = "POST"
},
new { @id = "ICLogRecommendationTypeAddForm" }
))
{*@
@Html.HiddenFor(model => model.ICLogID);
@Html.HiddenFor(model => model.SelectedIDs);
<div class="row form-group">
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
@Html.LabelFor(model => model.RecommendationTypes)
</div>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
@Html.DropDownListFor(model => model.RecommendationTypeID, new SelectList(Model.RecommendationTypes, "Value", "Text"), htmlAttributes: new { @class = "form-control", @id="selectedRecommendationType" })
</div>
</div>
<div class="row form-group">
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
@Html.LabelFor(model => model.Portfolios)
</div>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
@Html.DropDownListFor(model => model.PortfolioID, new SelectList(Model.Portfolios, "Value", "Text"), htmlAttributes: new { @class = "form-control", @id="selectedPortfolio" })
</div>
</div>
@using (Ajax.BeginForm("Log/Investment/Committee/Recommendation/Search", "References", new AjaxOptions
{
UpdateTargetId = "InvestmentSearchResults",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}, new { @id = "InvestmentSearchForm", @style = "flex-grow:1" }))
{
<div class="row form-group">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
@Html.LabelFor(model => model.Investments, "Investment Name", htmlAttributes: new { @class = "m-b-5" })
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 d-flex">
@Html.TextBoxFor(model => model.InvestmentSearchText, new { @class = "form-control m-r-10" })
<button id="InvestorSearchSubmit" data-submitform="true" data-formid="@{ WriteLiteral("InvestmentSearchForm"); } " class="btn btn-info m-r-10">Search</button>
</div>
</div>
}
<div id="InvestmentSearchResults" />
@*}*@
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<button class="btn btn-info pull-right" id="addRecommendationType">Add Recommendation Type</button>
</div>
</div>
<script>
$(document).ready(function () {
$("#addRecommendationType").click(function () {
var recTypeID = $('#selectedRecommendationType').val();
var portID = $('#selectedPortfolio').val();
var icLogID = $('#ICLogID').val();
var investmentID = $('input[type="checkbox"]:checked').val();
alert('test');
$.ajax({
type: "POST",
url: "@Url.Action("Log/Investment/Committee/RecommendationType/Create/Submit", "References")",
data: { 'icLogID': icLogID, 'recommendationTypeID': recTypeID, 'portfolioID': portID, 'investmentID': investmentID },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
},
error: function () {
return "error";
}
});
});
});
</script>
您的网址是您问题的原因:
url: "@Url.Action("Log/Investment/Committee/RecommendationType/Create/Submit", "References")"
改成:
url: @{Url.Action("Log/Investment/Committee/RecommendationType/Create/Submit", "References")}