Hi. I have to do a MVC project and I don't know exactly how to do it. on the clientside I will have an input form the data (at least two codes and up to 8) will be sent to the server (best way?) then the server will access a database and run a series of algorithms (i already have the code in vb from a previous windows forms app) and return 5 to 10 objects (numbers and strings) to the client which will display the results on a different view depending of the result. can anyone make a quick sketch of what i'll need to do? how to submit to server how to get it back controllers to send and get other languages/scripts I must use (js, ajax, etc) thanks

Dani AI

Generated

As suggested, send the codes as JSON and keep the server side responsible for validation, DB access and running your existing algorithms. Build this as three layers: a thin HTTP/API layer, a business-layer assembly that contains your VB algorithms (no UI code), and a small data/repository layer for DB access. That keeps the WinForms logic reusable and testable.

Move the algorithm code into a Class Library (VB) with a clear method like Run(codes As IEnumerable(Of String)) As List(Of ResultDto). Make it stateless (no shared mutable static fields), expose an interface (IAlgoService) and inject it into your controller. If an operation can take many seconds, don’t block request threads — either make the endpoint async or implement a background job (return a job id and let the client poll).

Example sketch (very small):

Public Class ComputeController
Inherits System.Web.Mvc.Controller

<HttpPost()>
Public Function Compute(req As ComputeRequest) As JsonResult
    If req.Codes Is Nothing OrElse req.Codes.Count < 2 OrElse req.Codes.Count > 8 Then
        Return Json(New With {.success = False, .error = "Provide 2–8 codes"})
    End If

    Dim results = _algoService.Run(req.Codes)
    Return Json(New With {.success = True, .results = results, .resultType = DetermineType(results)})
End Function

End Class

Client-side you can use fetch or jQuery.ajax to POST JSON; return a small envelope containing results plus a resultType (or view token) so the client knows which view to show or which server action to call next.

Hints and cautions: validate inputs server-side; parameterize DB queries; return meaningful HTTP codes (400/500); log and surface errors; write unit tests for the extracted algorithm DLL; and test concurrency to avoid thread-safety bugs. If you need help wiring up model-binding in VB MVC or choosing MVC action vs Web API for JSON endpoints, mention that and the sketch can be adapted to either approach.

Recommended Answers

All 2 Replies

If you use ajax to call your controller with json data, then mvc will take of converting that into your viewmodel on the server-side. You can then use the viewmodel results to pass back json data. Perhaps this link may help.

thanks a lot.

I did that and it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.