简体   繁体   中英

ASP.NET Core: Razor Page: Submit on Post: Hidden value

I'm new to Razor pages and am trying to post a form to my OnPostHandler method. I have a DevExpress SelectBox and an input type hidden field in my form and I keep track of the selectbox's selection changed in the hidden field. When I try to submit this form, I can see that the value of BatchType being submitted is null. How do I submit the BatchType to my handler? Any help is appreciated.

.cshtml:

@model SearchViewModel

<form asp-page-handler="TransactionsByAllSearch" method="post">
    <div class="myBox">
        <div class="inline-block">
            <div style="font-size: 15px;">Query Type</div>
            <div>
                @(Html.DevExtreme().SelectBox()
                .ID("querytypes")
                .ValueExpr("QueryType")
                .DisplayExpr("Description")
                .DataSource(Model.QueryTypes)
                .Width("300px")
                .DeferRendering(false)
                .DataSource(@Model.QueryTypes)
                .OnSelectionChanged("queryTypeSelectionChanged")
                    )
            </div>            
            <div>
                <input type="hidden" name="BatchType" value=""/>
            </div>
        </div>
</div>
<div>        
    @(Html.DevExtreme().Button().ID("getData").Text("Get Data").UseSubmitBehavior(true).Type(ButtonType.Success).Width(200))

</div>
</form>
<script>
    function queryTypeSelectionChanged(e){
        var batchType = $("#querytypes").dxSelectBox('instance').option('value');
        $('#BatchType').val(batchType);

    }
</script>

.cshtml.cs:

    [BindProperty]
    public SearchParameter ParameterModel { get; set; }
    public async Task<PageResult> OnPostTransactionsByAllSearch()
    {
           //do something with the ParameterModel
    }

SearchParameter.cs:

public class SearchParameter
    {
        public string BatchType{get;set;}
    }

My cshtml was a partial page and the hidden input filed wasn't assigned a value. I gave an "id" property to my hidden input and now I see the value being posted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM