gpt4 book ai didi

javascript - RadioButton 不访问搜索使用 Jquery Ajax

转载 作者:行者123 更新时间:2023-11-30 15:17:09 25 4
gpt4 key购买 nike

在这里,我尝试使用两个单选按钮、一个文本框和一个使用 jquery ajax 的按钮进行搜索。
现在的问题是,我检查的那个单选按钮的值始终是 TaskName 作为 Controller 的 searchByOption 的结果总是 TaskName.I.e 即使我选择了 AssignedTo 单选按钮 tha 值仍然是 TaskName

下面是我的 html

<div class="form-group input-group input-group-sm">
@Html.RadioButton("option", "TaskName") <text>TaskName</text>
@Html.RadioButton("option", "AssignedTo") <text> AssignedTo </text>
</div>

<div class="form-group input-group">
<input type="text" name="table_search" id="txtSearch" class="form-control pull-right" placeholder="Search--">
<span class="input-group-btn">
<button class="btn btn-default" id="btnSearch" type="submit"><i class="fa fa-search"></i></button>
</span>
</div>


下面是我的 jquery Ajax

<script>
$(document).ready(function () {
$(document).on('click', "#btnSearch", function () {
debugger;
var paramSprintNo = $("#getSprintNumber").val();

var searchOption = $("#option").val();

var searchElement = $("#txtSearch").val();

var paramProjectid = $("#getNewProjectId").val();

var paramsStatus = 30;

var parameter = { sprintNo: paramSprintNo, ProjectId: paramProjectid, searchString: searchElement, searchByOption: searchOption, status: paramsStatus };
debugger;
$.ajax({
url: "/TaskMains/Search",
type: "get",
dataType: "html",
data: parameter,
success: function (data) {
debugger;
$(".searchedContent").html("");
$(".searchedContent").html(data);
}
})
});
});
</script>


下面是 Controller

 public ActionResult Search(int status, int sprintNo, int ProjectId, string searchString, string searchByOption)
{
var taskmaninss = (from S in db.TaskMains
join T in db.TaskIterations on S.TaskId equals T.TaskId
join TA in db.TaskAssigneds on S.TaskId equals TA.TaskId
join IT in db.Iterations.Where(x => x.Name.Equals("Sprint " + Math.Abs(sprintNo)) && x.ProjectId == ProjectId) on T.IterationId equals IT.IterationId
join A in db.AllStatus.Where(x => x.StatusFor == 10) on S.Status equals A.Status
select new { S.TaskName, S.ProjectId, A.StatusName, S.Status, S.TaskId, S.PercentCompleted, TA.ProjectMember.MemberId, TA.ProjectMember.User.UsrName }).ToList();
var tasklist = taskmaninss.Select(x => new TaskBySprintViewModel()
{
TaskName = x.TaskName,
Status = x.Status,
TaskId = x.TaskId,
PercentCompleted = x.PercentCompleted,
MemberId = x.MemberId,
MemberName = x.UsrName,
ProjectId = x.ProjectId,
StatusName = x.StatusName

}).OrderBy(x => x.StatusName).ToList();


if (searchByOption == "AssignedTo")
{

ViewBag.sprintName = "Sprint " + Math.Abs(sprintNo).ToString();
var searchedTasklistByUserName = tasklist.Where(n => n.MemberName == searchString).ToList();
return PartialView("_InprogressTasklist", searchedTasklistByUserName.ToList());
}
else if (searchByOption == "TaskName")
{
ViewBag.sprintName = "Sprint " + Math.Abs(sprintNo).ToString();
var searchedtasklistbytaskname = tasklist.Where(x => x.TaskName == searchString || searchString == null).ToList();

return PartialView("_inprogresstasklist", searchedtasklistbytaskname.ToList());

}
else
{
return PartialView("_InprogressTasklist", tasklist.ToList());
}
}

最佳答案

这将返回第一个单选按钮的值

var searchOption = $("#option").val();

试试这个

var searchOption = $("#option:checked").val();

关于javascript - RadioButton 不访问搜索使用 Jquery Ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44297893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com