Guide on how to submit x-editable input data in a Razor page

When the submit button is clicked, I would like the form to be sent using the post method. Thank you for your assistance.
Here is the HTML code:

                                <form method="post" class="form-horizontal editor-horizontal">
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <a href="#" id="name" data-type="text"
                                               data-pk="1" data-placeholder="Required"
                                               data-title="Enter Your Name"&bt;@Model.Information.Doctor.Name</a>
                                        </div>
                                        <label class="col-sm-3 control-label">Name</label>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <a data-pk="1" data-placeholder="Required" data-placement="left"
                                               data-title="Enter Your Last Name" data-type="text"
                                               href="#" id="family" >@Model.Information.Doctor.Family</a>
                                        </div>
                                        <label class="col-sm-3 control-label">Last Name </label>
                                    </div>
                           
                                    <button type="submit" class="btn btn-primary"  >Submit</button>/>
                             </form>

This is my post method:

        public IActionResult OnPost(EditDoctorViewModel command)
        {
           var user= _service.EditDoctor(command);

           return Page();

        }

Answer №1

If you need to submit a form using the post method, make sure to include the appropriate input elements in your view. Below is an example code snippet:

Model:

public class EditDoctorViewModel
    {
        public Information information { get; set; }
    }

public class Information
    {
        public Doctor Doctor { get; set; }
    }

public class Doctor
    {
        public string Name { get; set; }
        public string Family { get; set; }
    }

View:

<form method="post" class="form-horizontal editor-horizontal">
     <div class="form-group">
       <label class="col-sm-3 control-label" >Name</label>
       <input type="text" asp-for="command.information.Doctor.Name" />
     </div>
     <div class="form-group">                             
         <label class="col-sm-3 control-label" >Last Name</label>
         <input type="text" asp-for="command.information.Doctor.Family" />
     </div>
     <button type="submit" class="btn btn-primary">Submit</button>
</form>

Controller:

public EditDoctorViewModel command { get; set; }
public Information Information { get; set; }

public IActionResult OnPost([FromForm]EditDoctorViewModel command)
{
    //var user = _service.EditDoctor(command);

    return Page();
}

You can then retrieve the submitted values in the Post Method. https://i.sstatic.net/18gOQ.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

showing information from a table column

Utilizing the jQuery DataTables plugin with a JSF <h:dataTable>. The page contains 86 records. +++++++++++++++++++++++++++++++++++++ + SN. + Name + Email + +++++++++++++++++++++++++++++++++++++ + 1 + Name 1 + Email 1 + + ...

Creating NextJS Route with Dynamic Links for Main Page and Subpages

In my NextJS project, I have dynamic pages and dynamic subpages organized in the following folders/files structure: pages ├── [Formation] ├── index.js │ ├── [SubPage].js Within index.js (Formation Page), I create links like this: < ...

Can anyone assist with troubleshooting the font size issue for a JavaScript tooltip on Joomla 1.5 with CK Forms?

My Joomla 1.5 site has CK Forms installed and is functioning properly, except for one issue: the tooltip on the captcha is not displaying correctly. It appears in a tiny 1px font size. Even though I have tried debugging using Firebug and confirmed that the ...

Problem concerning F# Plotly.NET graph explanations

Trying to create a line chart with a description using the method outlined in this link. The code executes without errors, and the chart is displayed correctly, but the description is not visible. Below is the code snippet: let description1 = ChartDe ...

Upon page reload in Nuxt.js middleware, Firebase authentication is returning as null

Just started with nuxtjs and using the Nuxt firebase library for firebase integration. After a successful login, I'm redirecting the user to the "/member/desk" route. However, if I refresh the page on that particular route, it redirects me back to "/a ...

Tips for encoding ParsedUrlQuery into a URL-friendly format

Switching from vanilla React to NextJS has brought about some changes for me. In the past, I used to access my URL query parameters (the segment after the ? in the URL) using the useSearchParams hook provided by react-router, which returned a URLSearchPara ...

Unlocking the Secret: How to Bind a Global Touch Event Handler in Angular 4 to Prevent iOS Safari Page Drag

The issue at hand is that within my Angular 4 application, there is a D3.js chart that relies on user touch input for dragging a needle to a specific value. The drag functionality is triggered by 'touchstart', while the registration of the final ...

An error occurred when attempting to hide or show a jQuery loading animation

Here is the HTML code I am using: <div id="success_message" style="display:none"> <p>Good job!</p> </div> <div id="my-form"> <form> <input>....... (lots of inputs) <input id="my-btn" ...

Collecting all ContextMenuStrips

I have a UserControl with multiple ContextMenuStrips added via Visual Studio Designer. They are not assigned to any controls at design time because they are dynamically assigned to a specific "dropdown" button based on context. I have a custom Class that l ...

Assign a value to a locally scoped variable within an iteration in Angular 2

Within my Angular code, I have the following HTML snippet: <span *ngIf="ControllerType?.AttributeID =='Controller Type'"> <select multiple name="ControllerType.Default" [(ngModel)]="Contro ...

Utilizing BEM Class Names in React

How can I utilize the Post component in a way that assigns unique classes to new and old posts following BEM recommendations? Assign a unique className to every element Avoid cascading dependencies like (.posts-new post or .posts-old post) Each component ...

I need the title to be filled with the input data and the content to be filled with the textarea data

import React from 'react'; export default class CreateNote extend React.component { constructor(props) { super(props); this.state = {note:{title:" ",content:" "} }; console.log(this.state); ...

TabPanel with Grid component causes Error: The server-rendered UI does not match the initial UI, resulting in failed hydration

After completing all the necessary steps and transferring all the files from nextjs-with-typescript, everything seemed to be in order until I tried adding Grid inside the TabPanel in the code snippet below: import * as React from 'react'; Tabs fr ...

Error in Vue Google Maps: Marker not defined

I'm currently working on integrating a single location map using Google Maps in Vue 2 with Vue-google-maps-2. Despite using code that has successfully worked for other parts of the application where multiple markers are plotted from an array, I am enc ...

Am I utilizing React hooks correctly in this scenario?

I'm currently exploring the example, but I have doubts about whether I can implement it in this manner. import _ from "lodash"; ... let [widget, setWidgetList] = useState([]); onRemoveItem(i) { console.log("removing", i); ...

Display div - conceal div - pause for 15 minutes - continue the cycle

I have a challenging JavaScript task that I've been struggling with for quite some time. The goal is to display a div for 5 seconds, hide it, wait for 15 minutes, then show it again for another 5 seconds, and continue this process in an infinite loop. ...

Utilizing only JavaScript to parse JSON data

I couldn't find a similar question that was detailed enough. Currently, I have an ajax call that accesses a php page and receives the response: echo json_encode($cUrl_c->temp_results); This response looks something like this: {"key":"value", "k ...

What is the preferred method for transferring server-side data to JavaScript: Using Scriplets or making an AJAX call?

At the server side, there is a property file that contains a list of words separated by commas. words.for.js=some,comma,separated,words The goal is to convert these words into a JavaScript array. var words = [some,comma,separated,words]; There are two ...

The clash between Kendo UI and jQuery UI

I implemented Kendo UI for the date picker, and I'm looking to incorporate jQuery UI for the autocomplete feature. Upon adding the jQuery auto complete to my code, I encountered the following error: Uncaught TypeError: Cannot read property 'e ...

"Exploring the differences between request.body, request.params, and request.query

I am working with a client-side JS file that includes: agent = require('superagent'); request = agent.get(url); Afterwards, the code looks something like this: request.get(url) //or request.post(url) request.end( function( err, results ) { ...