我是Ap.net核心MVC的新手我在一个项目的中间。我正在尝试使用jquery创建一个url并将该值传递给表单提交上的控制器。我可以在单击按钮后执行功能后看到显示的值。我正在使用jQuery无法加载的下拉列表加载局部视图,并将值分配给文本框。但是,当我尝试在控制器中访问同一文件时,无法在下面找到它是我的完整代码。我可以访问除jquery设置之外的textbox值以外的所有其他值。
下面是我的观点
<form method="post" asp-action="Upsert" enctype="multipart/form-data">
<div class="row px-2 mx-2 backgroundWhite border">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@if (Model.NavId != 0)
{
<input type="hidden" asp-for="NavId" />
title = "Edit Navigation";
}
<div class="col-12">
<h2 class="text-primary">@title</h2>
<hr class="my-4">
</div>
<div class="col-8">
<div class="form-group row">
<div class="col-5">
<label asp-for="Title"></label>
</div>
<div class="col-7">
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<div class="col-5">
<label asp-for="Position"></label>
</div>
<div class="col-7">
<input asp-for="Position" class="form-control" />
<span asp-validation-for="Position" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<div class="col-5">
<label asp-for="NavigateUrl">NavigationUrl</label>
</div>
<div class="col-7">
<input asp-for="NavigateUrl" disabled id="NavigateUrl" name="NavigateUrl" class="form-control" style="color:#000 !important"/>
<span asp-validation-for="NavigateUrl" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<div class="col-5">
<label>Select Page</label>
</div>
<div class="col-7">
<select id="SelectPage" class="form-control">
<option value="-">Select Page</option>
<option value="Products">Products</option>
<option value="ProductDetails">Product Details</option>
</select>
</div>
</div>
</div>
<div class="col-12 selectDiv mt-2 mb-2">
</div>
<div class="form-group row col-8">
<div class="col-12 offset-4">
@if (Model.NavId != 0)
{
//Edit button and back to list
<partial name="_EditAndBackToListButton" model="Model.NavId" />
}
else
{
//Create button and back to list
<partial name="_CreateAndBackToListButton" />
}
</div>
</div>
</div>
@section Scripts{ <script> $(document).ready(function () { $('#SelectPage').change(function () { var selectedvalue = $(this).children("option:selected").val(); $(".selectDiv").load("/Admin/Nav/GetCategoryOrProducts", { option: selectedvalue }); }); }); </script> <script> var assignvalue = function (primaryId) { event.preventDefault(); var selectedvalue = $('#SelectPage').children("option:selected").val(); var navtext = $('#NavigateUrl'); var navurl = "/" + selectedvalue + "/" + primaryId; navtext.val(navurl); }; </script> @{ await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
我的控制器方法
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Upsert(Nav nav)
{
if (ModelState.IsValid)
{
if (nav.NavId == 0)
{
string navurl = HttpContext.Request.Form["NavigateUrl"].ToString(); // I am not able to get the value here it shows null
nav.NavigateUrl = navurl;
_unitOfWork.Nav.Add(nav);
}
else
{
_unitOfWork.Nav.Update(nav);
}
return RedirectToAction(nameof(Index));
}
return View();
}
我是Ap.net核心MVC的新手,我在一个项目的中间。我正在尝试使用jquery创建一个url,并将该值传递给表单提交上的控制器。 ..
我可以通过jquery访问除文本框值以外的所有其他值