I work on razor asp.net core .i face issue selectedbranchid is inside post form form is get selected value without any issue
but if i use another post and get selectedbranchid it become null why
so How to solve issue please
on page model
[BindProperty]
public string SelectedBranchId { get; set; }
Mohamed Azarudeen ZPosted Jun 25, 2023, 2:14 PM
In your code, it seems that you're trying to access the
SelectedBranchIdproperty outside thetag, which results in a null value. The reason for this behavior is that theSelectedBranchIdproperty is bound to the form's model during the form submission. When you access it outside the form, it loses its binding context and becomes null.To solve this issue, you have a couple of options:
Option 1: Move the
tag inside thetag:By placing the hidden input field (
) within thetag, it will retain the binding context and correctly pass the value ofSelectedBranchIdduring form submission.Option 2: Use a different approach to retrieve the
SelectedBranchIdvalue: If you need to access theSelectedBranchIdvalue outside the form or in a different post method, you can use theHttpContext.Request.Formcollection to retrieve the value directly. Modify your code as follows:In this approach, you access the
SelectedBranchIdvalue directly from theHttpContext.Request.Formcollection using its name. This allows you to retrieve the value even outside the form's model binding context.