Problem 1.
You may notice that any inputs above your MVC placeholder will work and any form inputs below your MVC placeholder will not POST.The problem is that traditional ASP.NET web forms applications work off the principle of having only one form. MVC does not. However, if you look at the rendered HTML you may notice you have more than one form. ASP.NET will cope with the first form up until the first closing form tag (
</form>
).Solution
Remove all form tags from your MVC pages that are causing the nested forms. This way there will only be one form per page and should therefore POST correctly. Your MVC pages will continue to POST as expected.
Problem 2.
So now your WebForms MasterPage and MVC page performs postbacks wherever there is a submit button as expected. The problem now is that you are going to have to handle that post back within your MVC page.Solution
Make a base Controller class that all Controllers in the solution should inherit for. (I deliberately didn't end the class name with Controller so that MVC doesn't try and use it on its own).
Here is the main part of my ControllerBase:
using System.Web.Mvc; namespace Web.Controllers { public class ControllerBase : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { //if there is a form being posted if (Request.Form != null && Request.Form.Count > 0) { //iterate though all form keys for (var i = 0; i < Request.Form.Count; i++) { //get the value of the form key/value in question var value = Request.Form[i]; //if this is the key/value form pair i want and it is not blank if (Request.Form.Keys[i].EndsWith("txtSiteSearch") && !string.IsNullOrWhiteSpace(value)) { //do something (this redirects to a page with the search value in the query string Response.Redirect("/search/?q=" + value); } } } base.OnActionExecuting(filterContext); } } }
This will run on every request just before the selected ActionMethod is encountered.
I am essentially looking for a particular form field to check if the user typed into the MasterPage's site search text box (with ID="txtSiteSearch") before clicking a form submit button. If they have I send them to the search page with the search text in the querystring.
Obviously, this example is specific to my needs but if you need the form to use a service or other methods, these are all possible too.
This blog is so useful.
ReplyDeleteGypsum false Ceiling in Chennai
Informative blog. I like it, Thanks for sharing.
ReplyDelete2 and 3 bhk flats in nungambakkam
Did I know about using forms before? Not exactly. Rather, when the use of mobile forms began and the need to master a huge amount of information, I understood the essence of this application https://form.com/form-software/offline-forms/. Maybe in the future, I will offer this to my colleagues.
ReplyDeleteاگر به دنبال طراحی حرفه ای وب سایت خود بدون هیچ مشکلی هستید و میخواهید وب سایتی در حد طراحی فروشگاه اینترنتی دیجی کالا داشته باشید.کافیست با ما تماس بگیرید
ReplyDeleteThis is a very great post and the way you express your all post details that is too good.thanks for sharing with us this useful post..
ReplyDeleteField Engineer is an online marketplace that connects businesses who have jobs with Telecom Engineers who have the skills and availability to complete them..
What Is Wireless Lan
Hi
ReplyDeleteThis is nice post.
To Know about why business continuity plan
Managed IT Services are increasing sophisticated, cost-effective, empowering and constantly evolving, but there is one truth you can carve in stone: Managed IT Services are transforming business operations as they redefine profitability.
ReplyDeletemanaged service provider nj
Permainan tembak ikan adalah permainan yang paling rame orang mainkan, apalagi jika pelayanannya yang sangat memuaskan bagi anda tentunya kalian pasti akan merasa sangat puas juga kan ?, bagi kalian yang sangat menyukai permainan tembak ikan bisa datang ke situs kami :)
ReplyDeleteAPLIKASI JOKER123 APK
aplikasi joker123 apk versi terbaru
download aplikasi joker123 apk
daftar akun slot joker123
DAFTAR AKUN SLOT JOKER123
daftar akun joker123 slot
tembak ikan joker123
joker123 live casino
LOGIN JOKER388 SLOT
daftar joker388
JOKER123 DEPOSIT PULSA
DOWNLOAD JOKER388 APK
joker388 download apk
aplikasi joker388 apk
daftar akun joker388
game tembak ikan joker123
daftar akun tembak ikan joker123
LINK ALTERNATIF JOKER123
link alternatif joker123 slot
daftar akun joker388
tembak ikan joker388
Permainan slot yang paling banyak diminati oleh semua orang, tentunya disitus kami dengan permainan slot terlengkap, pastinya akan membuat kalian betah permainan slot apa yang kalian dulu mainkan tentunya akan ada disini. silahkan kunjungi situs kami
ReplyDeleteAgen Slot Vivo Indonesia
agen resmi slot vivo Indonesia
agen resmi slot vivo
cara daftar slot vivo
daftar akun vivo
cara daftar vivo slot
vivo slot
daftar vivo tembak ikan
Login Vivo Slot
Deposit Pulsa Vivo Slot
Withdraw vivo slot
Livechat Vivo Slot Indonesia
aplikasi vivo
Were you aware that you can get instant payday loans in New Zealand? The Payday Loans New Zealand blog introduces you to a simple and quick process to receive a cash loan with no fuss. This is a great article to read before Christmas for anyone who is struggling for cash to pay for Christmas presents for their families!
ReplyDeleteIf You Need Instant loans then visit: https://www.paydayloansnz.co.nz/instant-loans/
Bottlecaps | Learn all about Red Wines
ReplyDeleteWe at Bottlecaps are all about drinking wine and feeling fine. After all, we offer 360 degree e-commerce liquor solutions from where you can also order your favorite liquor online.