My first post. Was thrown in the ring to write a razor app...
The app implements the PRG pattern whereby a search page is presented, the user enters a criteria, hits the search button and the result of the search is presented at the bottom of the same page. The items listed in the results table have a link that open
a detail page, which has a "back" link to the first page. All that was working...I made some changes along the way and now when I run the app for the first time, it comes up. I enter the search criteria, hit the submit button and the page fails with
you don't show the code, but most likely you are binding get to a value type (non-nullable) that is required by default. so the url requires the parameter. make it a nullable type if you want it optional.
Hi Bruce. Thank you for taking the time to answer. I have posted my code. I can see it. If you can't please let me know how to make it visible to you. In the meantime I am pasting it raw below. Not sure where exactly to make the parameter optional; I tried
@ page "{fileSearchCriteriaAuto?} and it did not make a difference.
***Unformatted code
[TempData]
public string FileSearchCriteriaAuto { get; set; }
public void OnGet()
{
if (!String.IsNullOrEmpty(FileSearchCriteriaAuto))
{
FileSearchCriteria = JsonConvert.DeserializeObject<SearchCriteria>(FileSearchCriteriaAuto);
public async Task<IActionResult> OnPostAsync()
{
FileName = Request.Form["fname"].ToString().Trim();
var elements = Request.Form.Where(e => e.Key.Contains("criteria")).ToList();
ContentSearchCriteria = new List<string>();
foreach (var ele in elements)
{
ContentSearchCriteria.Add(ele.Value.ToString().Trim());
}
FileSearchCriteria = new SearchCriteria(FileName, ContentSearchCriteria.ToList());
I could not reproduce your issue.Could you share the razor view?And share more detailed code that could reproduce your issue.
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
4 Posts
Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web address:...
May 26, 2020 04:50 PM|TheBugSlayer|LINK
Hello everyone!
My first post. Was thrown in the ring to write a razor app...
The app implements the PRG pattern whereby a search page is presented, the user enters a criteria, hits the search button and the result of the search is presented at the bottom of the same page. The items listed in the results table have a link that open a detail page, which has a "back" link to the first page. All that was working...I made some changes along the way and now when I run the app for the first time, it comes up. I enter the search criteria, hit the submit button and the page fails with
"Hmmm...can’t reach this page
Try this Make sure you’ve got the right web address: https://localhost:5001..."
Below is a simplified version of the code in the page model.
NB: I have tried passing a parameter to the OnGet method, from a property decorated with the
. Then the browser cannot render the page, as if the link is broken.
Does anyone know why the page won't open? Thank you in advance!
All-Star
58184 Points
15655 Posts
Re: Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web addre...
May 26, 2020 05:07 PM|bruce (sqlwork.com)|LINK
you don't show the code, but most likely you are binding get to a value type (non-nullable) that is required by default. so the url requires the parameter. make it a nullable type if you want it optional.
None
0 Points
4 Posts
Re: Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web addre...
May 26, 2020 05:50 PM|TheBugSlayer|LINK
Hi Bruce. Thank you for taking the time to answer. I have posted my code. I can see it. If you can't please let me know how to make it visible to you. In the meantime I am pasting it raw below. Not sure where exactly to make the parameter optional; I tried @ page "{fileSearchCriteriaAuto?} and it did not make a difference.
***Unformatted code
[TempData]
public string FileSearchCriteriaAuto { get; set; }
public void OnGet()
{
if (!String.IsNullOrEmpty(FileSearchCriteriaAuto))
{
FileSearchCriteria = JsonConvert.DeserializeObject<SearchCriteria>(FileSearchCriteriaAuto);
HasSearch = FileSearchCriteria.FileName.Length > 0 || FileSearchCriteria.Criteria.Exists(c => c.Trim().Length > 0);
ContentSearchCriteria = new List<string>();
ContentSearchCriteria.AddRange(FileSearchCriteria.Criteria);
if (!(TempData == null))
{
FileSearchCriteriaAuto = JsonConvert.SerializeObject(FileSearchCriteria);
TempData["FileSearchCriteriaManual"] = FileSearchCriteriaAuto;
if (TempData.ContainsKey("MatchedFilesJson"))
{
MatchedFiles = JsonConvert.DeserializeObject<List<FileProcessed>>(TempData["MatchedFilesJson"].ToString());
TempData.Keep();
}
}
FileName = FileSearchCriteria.FileName;
}
else
{
FileSearchCriteria = new SearchCriteria(string.Empty, 3);
}
}
public async Task<IActionResult> OnPostAsync()
{
FileName = Request.Form["fname"].ToString().Trim();
var elements = Request.Form.Where(e => e.Key.Contains("criteria")).ToList();
ContentSearchCriteria = new List<string>();
foreach (var ele in elements)
{
ContentSearchCriteria.Add(ele.Value.ToString().Trim());
}
FileSearchCriteria = new SearchCriteria(FileName, ContentSearchCriteria.ToList());
string criteria = JsonConvert.SerializeObject(FileSearchCriteria);
await LoadFilesAsync(FileName);
MatchedFilesJson = JsonConvert.SerializeObject(MatchedFiles);
TempData["MatchedFilesJson"] = MatchedFilesJson;
return RedirectToPage("/Index");
}
Contributor
4933 Points
4205 Posts
Re: Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web addre...
May 26, 2020 06:09 PM|DA924|LINK
Try this Make sure you’ve got the right web address: https://localhost:5001..."
Maybe, https is not being used. Maybe nothing is listening on TCP port 5001. Maybe the url is wrong.
All-Star
58184 Points
15655 Posts
Re: Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web addre...
May 26, 2020 07:13 PM|bruce (sqlwork.com)|LINK
but there is no:
in the sample code. the line you say breaks your code.
Contributor
2690 Points
874 Posts
Re: Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web addre...
May 27, 2020 09:26 AM|Rena Ni|LINK
Hi TheBugSlayer,
I could not reproduce your issue.Could you share the razor view?And share more detailed code that could reproduce your issue.
Best Regards,
Rena