skip to Main Content

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


  1. 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 example

       public async Task<IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }
    
    
            return RedirectToPage("./SendTo", new { version = Version, merID = MERID, acqID = AcqID  });
        }
    

    And on the target page, you should have a Get method that accepts and processes the parameters

        public async Task<IActionResult> OnGet(string version, string merId, string acqID)
        {
            //Do something with the parameters
            return Page();
        }
    
    Login or Signup to reply.
  2. Firstly,in your OnGet(),you set jccgetter with a new JCC model three times,so it will be set to new JCC { AcqID = "402971" }; finally.If you want to set the properties of jccgetter.You can set the properties one by one.And if you want to submit form to OnPostSubmit,you can use asp-page-handler in <form></form>.Here is a working demo:

    cshtml.cs:

    [BindProperty]
            public JCC jccgetter { get; set; } = new JCC();
     public void OnGet()
            {
                this.jccgetter.Version="1.0.0" ;
                this.jccgetter.MerID = "0011223344";
                this.jccgetter.AcqID = "402971";
    
            }
    
            public void OnPostSubmit()
            {
    
               JCC jcc = this.jccgetter;
            }
    

    cshtml:

    <form method="post" name="paymentForm" id="paymentForm" asp-page-handler="Submit">
    
    
        <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" />
        <input type="submit" value="submit" />
    </form>
    

    result:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search