Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js mixed with asp.net MVC for validation

I am an experienced .net developer and I am very competent using MVC. I have only just read up a little on react.js today and would like to try and get more into it.

Are there any .net MVC developers or there that have mixed a project up with MVC with good results? Most notably to do with validation.

Normally my C# classes have validation attributes on them. And I can mess around with model state errors to do more custom stuff server side.

How would you mix react validation with MVC? Or can it not be done?

EDIT Is there anyway to validate in React using the MVC attributes to save duplication of validation?

like image 447
eyeballpaul Avatar asked Feb 12 '15 21:02

eyeballpaul


People also ask

Can React be used with ASP.NET MVC?

ReactJS.NET makes it easier to use Facebook's React and JSX from C# and other . NET languages, focusing specifically on ASP.NET MVC (although it also works in other environments). It supports both ASP.NET 4 (with MVC 4 or 5), and ASP.NET Core MVC. It is cross-platform and can run on Linux via Mono or .

How do you integrate ReactJS in existing ASP.NET MVC app?

Adding ReactJS JSX file Once added, rename the File extension TSX to JSX. Once the File is added, the following code needs to be added to the file. Here a class HelloWorld is created which extends ReactJS Component. The render function returns an HTML Header element (H1) with a message in it.

Can I use React in razor pages?

If there are any legacy MVC Razor pages, this shiny new React app will integrate seamlessly.


1 Answers

I would recommend having your validation rules server-side, then passing a json object to the client with those validation rules. On the client, you can then create logic to validate these rules, and then once the form is submitted you can run the server-side validation rules and pass back any failed validation to the client.

like image 191
Jessie Schalles Avatar answered Sep 21 '22 15:09

Jessie Schalles