Asp.Net C# MVC Dynamic Forms (Changing Dom structure and getting data on the server)

前端 未结 3 555
失恋的感觉
失恋的感觉 2021-01-24 10:07

I dynamically change DOM on client-side to add some new input fields using JavaScript.

Can I obtain the data on the server-side without using Ajax? Just pushing send but

相关标签:
3条回答
  • 2021-01-24 10:51

    If you're posting the form, sure. You can use either the FormCollection to get the element you want, or explicitly identify the parameter in your method signature. Assume you added an input element with the name "myTextBox", you could do the following:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(int id, string myTextBox, FormCollection collection) {
    
      // better
      if (myTextBox != null) {
        // do something with the string
      }
    
      // good
      if (collection["myTextBox"] != null) {
        string textboxvalue = collection["myTextBox"].ToString();
      }
    
    }
    
    0 讨论(0)
  • 2021-01-24 10:52

    You need to add "name" attribute to the control, so the data will be sent to the server on form submit.

    0 讨论(0)
  • 2021-01-24 11:02

    ANSWER IS HERE: http://habrahabr.ru/blogs/aspnet_mvc/88766/, Don't pay attention to language, look code samples

    0 讨论(0)
提交回复
热议问题