Question

I'm trying to learn some ServiceStack stuff. For now, I've succesfully completed this tutorial (almost completed): http://www.ienablemuch.com/2012/12/self-hosting-servicestack-serving.html

The next step I want to perform is creating html form with submit button and capture data entered, for example into variables in C# code.

I know how to create html form inside cshtml file, but I have no idea how to caputre entered POST data in this case - with ServiceStack. Can you provide any tips/code samples.

Also, there is something I don't understand in this tutorial:

19 . To use strongly-typed model for your razor page, use inherits directive. Create a model first, it must be public and its Copy to Output Directory property must be set to Copy if newer too

What is this "Model" exactly and how to create it? And, section 20, in cshtml code:

@inherits ViewPage

So, what is "ViewPage" and how exactly this statement works?

Was it helpful?

Solution

Solved. So, what is needed to be done:

  • create public class with public properties inside. Properties names should match post/get values in my form

  • add this: @inherits ViewPage<BillionaireServiceStackRazorSelfHosting.MyClass> to cshtml

After form submit, corresponding properties are set. I don't know if this is good way (please correct me if it doesn't), but I've added some code to "set" handler inside MyClass property, instead of adding code to cshtml that uses captured values.

Everything seems to be working as I wanted to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top