I need help , I need to submit an html form containing hidden fields to another URL the values of the hidden fields some of them are static and some of them are dynamic (from code behind ) in webform , now i need to do this from asp.net razor page , with the code I have, only one hidden field value is detected appreciate your help.. also if i can know how to submit to the the other url !
below is my code
model class name : jcc
[BindProperty]
public string Version { get; set; }
[BindProperty]
public string MerID { get; set; }
[BindProperty]
public string AcqID { get; set; }
sendto.cshtml
@page
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@model saderlexstore.Pages.Admin.sendtoJCCModel
@{
ViewData["Title"] = "JCC Required Info";
}
<!DOCTYPE html>
<html lang="en">
<head>
<script>
function sss() {
document.forms["paymentForm"].submit();
}
</script>
</head>
<body>
<form method="post" name="paymentForm" id="paymentForm" >
<input type="text" name="Version" id="Version" asp-for="jccgetter.Version" />
<br />
<input type="text" name="MerID" id="MerID" asp-for="jccgetter.MerID" />
<br />
<input type="text" name="AcqID" id="AcqID" asp-for="jccgetter.AcqID" />
sendto.cshtml.cs
[BindProperty]
public JCC jccgetter { get; set; }
public void OnGet()
{
this.jccgetter = new JCC { Version = "1.0.0" };
this.jccgetter = new JCC { MerID = "0011223344" };
this.jccgetter = new JCC { AcqID = "402971" };
}
public void OnPostSubmit()
{
JCC jcc = this.jccgetter;}
2
Answers
I’m not very sure what exactly you are aiming at, but if you want to send submitted data from one Razor page to another Razor page you should you
RedirectToPage
with paremeters. For exampleAnd on the target page, you should have a
Get
method that accepts and processes the parametersFirstly,in your
OnGet()
,you set jccgetter with a new JCC model three times,so it will be set tonew JCC { AcqID = "402971" };
finally.If you want to set the properties ofjccgetter
.You can set the properties one by one.And if you want to submit form toOnPostSubmit
,you can useasp-page-handler
in<form></form>
.Here is a working demo:cshtml.cs:
cshtml:
result: