我如何...如何使用剃刀中填充的选项修复我的搜索 [英] How do i...how to fix my search using a select that is populated in razor

查看:63
本文介绍了我如何...如何使用剃刀中填充的选项修复我的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个按校园搜索员工的页面。校园里有一个使用剃须刀的人选。然后我得到了所有过滤的员工,但是页面拒绝用当前的员工数量重新绘制DOM



我有一个onchange的onchange()它叫ajax这将调用页面的ActionResult。这可以正常工作,因为它返回正确的数据。



我尝试过:



使用剃须刀填充的选择

 <  选择   占位符  = 选择校园    id   =  selCampus    class   =  form-control   必需 >  
< 选项 < span class =code-attribute> value = > 选择校园< / option >

@foreach(在Model.Campuses中的var campus)
{

< 选项 value = @ campus.Id > @ campus.CampusName < / option >

}
< / select >



指向动作控制器的选择的转换

 $(  #selCampus)。change( function (){
// $(。employee)。remove();
$ .ajax({
类型:' POST'
url:' / admin / staff /'
dataType:' html'
data:({
campusId:$( this )。 val()
}),
成功:功能(){
}
});
});





ActionResult,这会加载页面加载和更改选择

< pre lang =c#> public ActionResult Employees( long ?campusId)
{
var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString() );
var request = new RestRequest( api / employee / getClinicMembers / {campusId},Method.POST);
request.AddParameter( campusId,campusId,ParameterType.QueryString);

var result = client.Execute< ClinicMembersOutput>(request);

ViewBag.title = 主页|会员;
return 查看(result.Data);
}





不想用新数据重绘此代码,即使Model.Employees已过滤数据

 @ foreach(Model.Employees中的var成员)
{
< div class = col-lg-4 col-xlg-3 col-md-5员工 > ;
< div class = card >
< div class = card-body >

< / div >
< / div >


< / div > ;

}

解决方案

#selCampus)。change( function (){
//


(。employee)。remove();


.ajax({
类型:' POST'
url:' / admin / staff /'
dataType:' html'
data:({
campusId:


have a page that searches employees by campus. The campuses are populated in a select using razor. I then get all the filtered employees but the page refuses to redraw the DOM with the current number of employees

I have an onchange() of the select it calls an ajax that will call the ActionResult of the page. This somehow works fine since it returns the correct data.

What I have tried:

A select populated using razor

<select placeholder="Select campus" id="selCampus" class="form-control" required>
                                <option value="">Select campus</option>

                                @foreach (var campus in Model.Campuses)
                                {

                                    <option value="@campus.Id">@campus.CampusName</option>

                                    }
                                </select>


Onchange for the select pointing to the action controller

$("#selCampus").change(function () {
                //$(".employee").remove();
                $.ajax({
                    type: 'POST',
                    url: '/admin/staff/',
                    dataType: 'html',
                    data: ({
                        campusId: $(this).val()
                    }),
                    success: function () {
                    }
                });
            });



ActionResult, this loads on pageload and onchange of the select

public ActionResult Employees(long? campusId)
                {
                    var client = new RestClient(Request.Url.GetLeftPart(UriPartial.Authority).ToString());
                    var request = new RestRequest("api/employee/getClinicMembers/{campusId}", Method.POST);
                    request.AddParameter("campusId", campusId, ParameterType.QueryString);

                    var result = client.Execute<ClinicMembersOutput>(request);

                    ViewBag.title = "Home | Members";
                    return View(result.Data);
                }



Does not want to redraw this code with new data, Even tho Model.Employees has filtered data

@foreach (var member in Model.Employees)
                        {
                            <div class="col-lg-4 col-xlg-3 col-md-5 employee">
                                <div class="card">
                                    <div class="card-body">

                                    </div>
                                </div>


                            </div>

                        }

解决方案

("#selCampus").change(function () { //


(".employee").remove();


.ajax({ type: 'POST', url: '/admin/staff/', dataType: 'html', data: ({ campusId:


这篇关于我如何...如何使用剃刀中填充的选项修复我的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆