have a good time
How can I save the form values as a string after the page is redirected?
I use a static variable, if the number of users on the site increases for example 20000, will the site have problems?
Which method is better?
Using a static variable?
session?
Cookies?
ViewBag?
View State?
sql server database?
CodePudding user response:
Actually, There is no the best method, Only the most suitable method. The methods you list above all have their own most suitable use cases.
From your comment, I think you may wanna redirect to another page with a string parameter, So you can try to use :
return RedirectToAction("actionName","controllerName",new { Name="xxx"});
It will send a get request: acontrollerName/actionName?Name=xxx
.
Or, if you wanna save that string value for a long time, You can also try to use Session
or Database
. But one thing you need to consider is that you need to set the session time out according to the actual situation of your project.
CodePudding user response:
no i dont want to redirect to other page i want give string value after refresh current page How can I save the form values as a string after the page is refreshed?
this is my model:
public int ID { get; set; }
public string Name { get; set; }
static variable:
public static int IDWordsaver = 0;
On Get for MyPage:
public async Task<IActionResult> OnGetAsync()
{
await LoadAsync();
return Page();
}
private async Task LoadAsync()
{
if (IDWordsaver != 0)
{
var SetRecord = _db.Table.FirstOrDefault(u => u.ID == IDWordsaver);
ID = IDWordsaver;
Input = new InputModel
{
Name = SetRecord.Name
};
}
}
i use this button for select one record from data base:
<button asp-page-handler="SelectMenu" name="selectedid" [email protected] formnovalidate>Select</button>
public async Task<IActionResult> OnPostSelectMenu(int selectedid)
{
var selected = await _db.Table.FindAsync(selectedid);
ID = selected.ID;
Input.Name = selected.Name;
IDWordsaver = selectedid;
return RedirectToPage("MyPage", new { IDWordsaver });
}