I'm not sure how this will look in VB, but in C # (and in the spirit of MVC) you will need 3 things:
Model:
public class SomeModel { [DisplayName="Param One"] public String ParamOne{get; set;} [DisplayName="Param Two"] public String ParamTwo{get; set;} }
View:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SomeModel>" %> <asp:Content ID="SomeID" ContentPlaceHolderID="TitleContent" runat="server"> A title for your page </asp:Content> <asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server"> <% using (Html.BeginForm("Process", "SomeModel", returnURL)) {%> <%= Html.LabelFor(m => m.ParamOne)%>: <%= Html.TextBoxFor(m => m.ParamOne)%> <%= Html.LabelFor(m => m.ParamTwo)%>: <%= Html.TextBoxFor(m => m.ParamTwo)%> <%--- A button ---%> <input type="submit" value="Press Me" /> <% } %> <%--- Display Errors ---%> <%= Html.ValidationSummary()%> </asp:Content>
Controller:
public class SomeModelController:Controller { [HttpPost] public ActionResult Process(SomeModel model) { Validate(model); return View(model); } private bool Validate(SomeModel model) { if() { return true; } else { ModelState.AddError("error", "Some error message"); return false; } } }
Please note that in this case, any validation errors will appear on the same page on which they were entered. If you want to change this, you will have to change the controller and add more views:
[HttpPost] public ActionResult Process(SomeModel model) { if(ModelState.IsValid && Validate(model)) { return RedirectToAction("Success", "SomeModel"); } else { return RedirectToAction("Failure", "SomeModel"); } } [HttpGet] public ActionResult Success(SomeModel model) { return View(model);
As I said, this is in C #, but it’s not so difficult to translate to VB ... In addition, this is just a general approach to the problem, you may have to tweak a few things to actually work properly. It should be noted here that the MVC pattern may seem a little cumbersome at the beginning, i.e. For a simple button, you need to write A LOT code, but it pays off when you have a complex application.
Kiril source share