-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1744 from riganti/support-classic-post-forms
Add back support for manually handling POST requests
- Loading branch information
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Samples/Common/ViewModels/FeatureSamples/NoJsForm/NoJsFormViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.NoJsForm | ||
{ | ||
public class NoJsFormViewModel : DotvvmViewModelBase | ||
{ | ||
public string Form1Value { get; set; } | ||
public string Form2Value { get; set; } | ||
|
||
public override async Task Load() | ||
{ | ||
var req = Context.HttpContext.Request; | ||
if (req.Method == "POST") | ||
{ | ||
using var body = new StreamReader(req.Body); | ||
var data = HttpUtility.ParseQueryString(await body.ReadToEndAsync()); | ||
var submit = data["submit"]; | ||
if (submit == "form1") | ||
{ | ||
Form1Value = data["text"]; | ||
} | ||
else if (submit == "form2") | ||
{ | ||
Form2Value = data["text"]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
src/Samples/Common/Views/FeatureSamples/NoJsForm/NoJsForm.dothtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@viewModel DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.NoJsForm.NoJsFormViewModel, DotVVM.Samples.Common | ||
|
||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
</head> | ||
<body> | ||
<div RenderSettings.Mode=Server> | ||
<fieldset> | ||
<legend>Form 1</legend> | ||
<form method="POST"> | ||
<input id=input1 type="text" name="text" /> | ||
<button id=submit1 type=submit name=submit value=form1>Submit</button> | ||
|
||
<p Visible={value: Form1Value != null}> | ||
Last submitted value: <span id=result1>{{value: Form1Value}}</span> | ||
</p> | ||
</form> | ||
</fieldset> | ||
|
||
<fieldset> | ||
<legend>Form 2</legend> | ||
<form method="POST"> | ||
<input id=input2 type="text" name="text" /> | ||
<button id=submit2 type=submit name=submit value=form2>Submit</button> | ||
|
||
<p Visible={value: Form2Value != null}> | ||
Last submitted value: <span id=result2>{{value: Form2Value}}</span> | ||
</p> | ||
</form> | ||
</fieldset> | ||
</div> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DotVVM.Samples.Tests.Base; | ||
using DotVVM.Testing.Abstractions; | ||
using Riganti.Selenium.Core; | ||
using Riganti.Selenium.DotVVM; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace DotVVM.Samples.Tests.Feature | ||
{ | ||
public class NoJsFormTests : AppSeleniumTest | ||
{ | ||
[Fact] | ||
public void Feature_NoJsForm_NoJsForm() | ||
{ | ||
RunInAllBrowsers(browser => { | ||
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_NoJsForm_NoJsForm); | ||
|
||
browser.SendKeys("#input1", "Q"); | ||
browser.Click("#submit1"); | ||
AssertUI.InnerTextEquals(browser.First("#result1"), "Q"); | ||
|
||
browser.SendKeys("#input2", "W"); | ||
browser.Click("#submit2"); | ||
AssertUI.InnerTextEquals(browser.First("#result2"), "W"); | ||
}); | ||
} | ||
|
||
public NoJsFormTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
} | ||
} |