1
            <form method="post" id="modalForm" action="/Test/TestForm" target="myframe">
                <input type="text" name="id" required />
                <input type="text" name="name" required />
                <input type="submit" value="Post" onsubmit="alert('after post!');" />
            </form>

    [HttpPost]
    public IActionResult TestForm(Test test)
    {
        return View();
    }

    public class Test
    {
        public string id;
        public string name;
    }

What needs to be changed, on the form, to get values to the Test class? Currently the values are null? I would like to keep it simple, without ASP.NET Core helpers.

2
  • Change TestForm(Test test) to TestForm([FromForm]Test test) Commented May 30, 2020 at 5:06
  • You need to use properties (get/set) and not fields Commented May 30, 2020 at 8:17

1 Answer 1

1

C# provides a way to use short-hand / automatic properties where you only have to write get; and set; inside the property.

    public class Test
    {
        public string id { get; set; }
        public string name { get; set; }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.