简体   繁体   中英

Getting value from a Masterpage in the controller Asp.Net MVC

如何获得放置在母版页中的文本框的价值?

I agree with Pete.

Sometimes it is convenient to put general items into the master page. In contrast to classic asp.net it is harder to get the value with every post. In classic asp.net there is only one formular on the html page wich will be posted and all works well. In mvc there could be more formulars on the page. You have to put the textbox into a every form to get the value in every post - no solution.

A custom user control (ascx) might be a solution. Put the textbox in and place the custom control into the form where you need the value. If you have more forms or a complicated layout, than it is no solution.

A hidden field might be a solution. Replicate value changes of your original textbox into hidden fields placed in the formulars where you need the value.

I would find another solution. The purpose of master pages is to decouple the general layout from the specific pages (or controllers). You should be free to change the master pages without breaking the application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM