(MVC) MVC (2018)

The ways to receive complex parameters in ASP.NET


There are some choice to receive parameters in ASP.NET. In this page I'm describe most of it. This is real workable code, therefore as example to first part code below, I'll use this form.


   9:      <form role="form" name="resumeform" id="resumeform" method="post" enctype="multipart/form-data" action="/api/Upload/PostResumeData">
  10:          <div class="col-md-1 panel1" style="border:none">
  11:          </div>
  12:          @Html.Partial("~/Views/Resume/PostSetSkillPanel.vbhtml")
  13:          <div class="col-md-7 panel1">
  14:              <h2>Please fill all fields in your public resume </h2>
  15:              <div style="max-height: 750px; min-height:750px; overflow: auto;">
  16:                  <div class="form-group">
  17:                      <label for="Title"><span style="color:red">*</span> Title of your bean </label>
  18:                      <input class="form-control" id="title" name="title" placeholder="No more than 100 chars.">
  19:                  </div>
  20:                  <div class="form-group">
  21:                      <label for="InputPDFFile">Upload PDF files with your resume</label>
  22:                      <input type="file" class="form-control-file" id="InputPDFFile" name="InputPDFFile">
  23:                      <p class="help-block">This pdf files not will be parsed or changed.</p>
  24:                  </div>
  25:                  <div class="form-group">
  26:                      <label for="InputAvaFile">Upload your Avatar (if necessary)</label>
  27:                      <input type="file" class="form-control-file" id="InputAvaFile" name="InputAvaFile">
  28:                      <p class="help-block">Will be reduced to 100x100 px</p>
  29:                  </div>
  30:                  <div class="form-group">
  31:                      <label for="Short-description"><span style="color:red">*</span> Enter description for customer </label>
  32:                      <textarea class="form-control" id="Short-description" rows="7" placeholder="No more than 1000 chars." name="Short-description"></textarea>
  33:                  </div>
  34:                  <div class="form-group">
  35:                      <label for="Publiccontacts"><span style="color:red">*</span> Enter your public contacts for customer </label>
  36:                      <input class="form-control" id="Publiccontacts" placeholder="Any your public contact in free form, No more than 100 chars." name="Publiccontacts"">
  37:                  </div>
  38:                  <div class="form-group">
  39:                      <label for="AdminContacts">Enter your email for Sign in to this site. </label>
  40:                      <input type="email" class="form-control" id="AdminContacts" placeholder="We sent password to this email." name="AdminContacts">
  41:                      <span style="color:red">*</span> or <br />
  42:                      <label for="Publiccontacts">Sign In using another account</label>
  43:                      <a class="oauth" alt="Sign in using Github" title="Sign in using Github" href="/script/Membership/OAuthLogOn.aspx?auth=GitHub"><img src="/Images/octicons_github-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  44:                      <a class="oauth" alt="Sign in using Linkedin" title="Sign in using Linkedin" href="/script/Membership/OAuthLogOn.aspx?auth=LinkedIn"><img src="/Images/linkedin-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  45:                      <a class="oauth" alt="Sign in using Facebook" title="Sign in using Facebook" href="/script/Membership/OAuthLogOn.aspx?auth=Facebook"><img src="/Images/facebook-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  46:                      <a class="oauth" alt="Sign in using Google" title="Sign in using Google" href="/script/Membership/OAuthLogOn.aspx?auth=Google"><img src="/Images/google-plus-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  47:                      <a class="oauth" alt="Sign in using Microsoft" title="Sign in using Microsoft" href="/script/Membership/OAuthLogOn.aspx?auth=Microsoft"><img src="/Images/microsoft-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  48:                  </div>
  49:                  <button id="PostResume" name="PostResume" type="submit" class="btn btn-primary">Post Resume</button>
  50:              </div>
  51:          </div>
  52:      </form>
  53:  </div>
  54:   

1. WebHandler - the simplest and universal way to receive any parameters in ASP.NET.

First, simplest and common choice is exclude any specific Microsoft complicated superstructure. And receive form parameters with simple ASP.NET Handler (.ASHX). This way I use in most situation when I have difficulties with built in Microsoft processing of parameters. And this is oldest way to receive parameters in ASP.NET MVC, what exist in ASP.NET over 15 years.

Complex parameters usually reading by MultipartParser and there are two way to read simple POST parameters. First way, if POST-parameters packed with rules content type application/x-www-form-urlencoded, it usually receive as context.Request.Form("Prm1"), otherwise its can read as raw stream, like below (this is template of security activator, that receive GUID-string and return 20-chars code for activation program, but in reality, of cource, string 15 is more complex).


   1:  Imports System.Web
   2:  Imports System.Web.Services
   3:   
   4:  Public Class GetCode
   5:      Implements System.Web.IHttpHandler
   6:   
   7:      Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
   8:          Dim Str1 As String
   9:          Using reader = New IO.StreamReader(context.Request.InputStream)
  10:              Str1 = reader.ReadToEnd()
  11:          End Using
  12:          If Not String.IsNullOrWhiteSpace(Str1) Then
  13:              Dim Hash As Byte()
  14:              Using Md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
  15:                  Hash = Md5.ComputeHash(Encoding.UTF8.GetBytes(Str1))
  16:              End Using
  17:              Dim RespString As String = Convert.ToBase64String(Hash)
  18:              context.Response.ContentType = "text/plain"
  19:              context.Response.Write(Left(RespString, Len(RespString) - 4))
  20:          End If
  21:      End Sub
  22:   
  23:      ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
  24:          Get
  25:              Return False
  26:          End Get
  27:      End Property
  28:   
  29:  End Class

Post-parameters in this case is sending as raw string, like this.


   1:  Imports System.IO
   2:  Imports System.Net
   3:  Imports System.Text
   ...   
   9:          Dim Html = PostRequest("http://s5.programmer.expert/GetCode.ashx", ID.ToString)
   ...   
  26:      Public Function PostRequest(Url As String, PostData As String)
  27:          Dim Html As String
  28:          Dim ByteArray As Byte() = Encoding.UTF8.GetBytes(PostData)
  29:          Dim Request As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
  30:          Request.AutomaticDecompression = DecompressionMethods.GZip
  31:          Request.Method = "POST"
  32:          Request.ContentType = "application/x-www-form-urlencoded"
  33:          Request.ContentLength = ByteArray.Length
  34:          Dim DataStream As Stream = Request.GetRequestStream()
  35:          DataStream.Write(ByteArray, 0, ByteArray.Length)
  36:          DataStream.Close()
  37:          Using Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
  38:              Using Stream As Stream = Response.GetResponseStream()
  39:                  Using Reader As StreamReader = New StreamReader(Stream)
  40:                      Html = Reader.ReadToEnd()
  41:                  End Using
  42:              End Using
  43:          End Using
  44:          Return (Html)
  45:      End Function

2. WebAPI - modern alternative way to receive complex parameter without model.

Firstly and main point you must understanding - this way not faster, not better, not simple than any old way is listed in previous point - WEbMethod (from Classic ASP.NET), simple WebHandler or independent library like MultipartFormDataParser - this is only a small additional way to doing the same job.

And second point you must understanding - there are some alternative way with using WebAPI to doing the same job to receive complex multipart/form-data parameters. And third main point - this is a way to receive RAW parameters without Model.

And below you may see my first variant of code. This is simplest way to receive multipart/form-data parameters by MultipartFormDataStreamProvider. This class firstly automatically saved uploaded files to TMP directory and after that move files to right place with right name. And as a result it return name of uploaded files.



   1:  Imports System.Net
   2:  Imports System.Net.Http
   3:  Imports System.Web.Http
   4:   
   5:  Namespace Controllers
   6:      Public Class UploadController
   7:          Inherits ApiController
   8:   
   9:          <HttpPost>
  10:          Public Async Function PostResumeData() As Threading.Tasks.Task(Of HttpResponseMessage)
  11:   
  12:              If Request.Content.IsMimeMultipartContent() Then
  13:                  Dim UploadedFileList As List(Of KeyValuePair(Of String, String)) = Await FileDataReader1("~/App_Data/tmp/", "~/App_Data/")
  14:              End If
  15:   
  16:              Dim Response = Request.CreateResponse(HttpStatusCode.Moved)
  17:              Response.Headers.Location = New Uri("http://localhost:54598/Project/Search") 'Return RedirectToAction("Search", "Project")
  18:              Return Response
  19:   
  20:          End Function
  21:   
  22:          Async Function FileDataReader1(TmpRoot As String, UserRoot As String) As Threading.Tasks.Task(Of List(Of KeyValuePair(Of String, String)))
  23:   
  24:              Dim TmpRootDir As String = HttpContext.Current.Server.MapPath(TmpRoot)
  25:              Dim StreamProvider = New System.Net.Http.MultipartFormDataStreamProvider(TmpRootDir)
  26:              Dim RDR = Await Request.Content.ReadAsMultipartAsync(StreamProvider)
  27:   
  28:              Dim UploadedFileList = New List(Of KeyValuePair(Of String, String))
  29:   
  30:              Try
  31:                  For Each FileData As Net.Http.MultipartFileData In StreamProvider.FileData
  32:   
  33:                      If Not String.IsNullOrWhiteSpace(FileData.Headers.ContentDisposition.FileName) Then
  34:                          'Uploading file
  35:                          Dim FileName = FileData.Headers.ContentDisposition.FileName.Replace("""", "")
  36:                          If Not String.IsNullOrWhiteSpace(FileName) Then
  37:                              Dim UserFileName As String = IO.Path.Combine(HttpContext.Current.Server.MapPath(UserRoot), FileName)
  38:                              IO.File.Move(FileData.LocalFileName, UserFileName)
  39:                              Dim Key1 = FileData.Headers.ContentDisposition.Name.Replace("""", "")
  40:                              UploadedFileList.Add(New KeyValuePair(Of String, String)(Key1, FileName))
  41:                          End If
  42:                      End If
  43:                  Next
  44:   
  45:                  Return UploadedFileList
  46:   
  47:              Catch e As System.Exception
  48:                  Throw New Web.Http.HttpResponseException(e.Message)
  49:              End Try
  50:   
  51:          End Function
  52:   
  53:      End Class
  54:  End Namespace

The second variant of code is more interesting, It still based on task-based programming model wait Async/Await, still parse parameters from the same form. but instead complex class MultipartFormDataStreamProvider is parse directly input content by StreamReader. Therefore additionally to upload files this variant of code is receive simple parameters from form, not only uploaded files.

Also this way give opportunity to receive not only one string parameters, but directly all receiving data to NameValueCollection.



  17:                  Dim FormValues As List(Of KeyValuePair(Of String, String)) = Await FileDataReader2(AddressOf MyFileProcessor)
  57:   
  58:          Async Function FileDataReader2(ByVal FileProcessor As Action(Of String, IO.Stream)) As Threading.Tasks.Task(Of List(Of KeyValuePair(Of String, String)))
  59:   
  60:              Dim StreamContent = New Http.StreamContent(HttpContext.Current.Request.InputStream)
  61:              StreamContent.Headers.ContentType = Net.Http.Headers.MediaTypeHeaderValue.Parse(HttpContext.Current.Request.ContentType)
  62:              Dim StreamProvider = Await StreamContent.ReadAsMultipartAsync()
  63:   
  64:              Dim FormValues = New List(Of KeyValuePair(Of String, String))
  65:   
  66:              Try
  67:                  For Each HttpContent In StreamProvider.Contents
  68:   
  69:                      If Not String.IsNullOrWhiteSpace(HttpContent.Headers.ContentDisposition.FileName) Then
  70:                          Dim FileName = HttpContent.Headers.ContentDisposition.FileName.Replace("""", "")
  71:                          If Not String.IsNullOrWhiteSpace(FileName) Then
  72:                              'Uploading file
  73:                              Using FileContents As IO.Stream = Await HttpContent.ReadAsStreamAsync()
  74:                                  FileProcessor(FileName, FileContents)
  75:                              End Using
  76:                              Dim Key1 = HttpContent.Headers.ContentDisposition.Name.Replace("""", "")
  77:                              FormValues.Add(New KeyValuePair(Of String, String)(Key1, FileName))
  78:                          End If
  79:                      Else
  80:                          'simple value
  81:                          Dim Val1 = Await HttpContent.ReadAsStringAsync
  82:                          Dim Key1 = HttpContent.Headers.ContentDisposition.Name.Replace("""", "")
  83:                          FormValues.Add(New KeyValuePair(Of String, String)(Key1, Val1))
  84:                      End If
  85:                  Next
  86:   
  87:                  Return FormValues
  88:   
  89:              Catch ex As Exception
  90:                  Throw New Web.Http.HttpResponseException(ex.Message)
  91:              End Try
  92:   
  93:          End Function
  94:   
  95:          Private Function MyFileProcessor(FileName As String, FileContents As IO.Stream)
  96:              Dim UserRootDir As String = HttpContext.Current.Server.MapPath("~/App_Data/")
  97:              Dim ResFileName As String = IO.Path.Combine(UserRootDir, FileName)
  98:              Using FS = New IO.FileStream(ResFileName, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
  99:                  FileContents.CopyToAsync(FS)
 100:              End Using
 101:              Return ResFileName
 102:          End Function

There are one small differences to use directly WebHandler and WebApi, so far as WebApi is processed by IIS Route, we must tune RouteConfig class.


   1:  Imports System
   2:  Imports System.Collections.Generic
   3:  Imports System.Linq
   4:  Imports System.Web
   5:  Imports System.Web.Mvc
   6:  Imports System.Web.Routing
   7:   
   8:  Public Module RouteConfig
   9:      Public Sub RegisterRoutes(ByVal routes As RouteCollection)
  10:          routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
  11:   
  12:          routes.MapRoute(
  13:              name:="Default",
  14:              url:="{controller}/{action}/{id}",
  15:              defaults:=New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional}
  16:          )
  17:      End Sub
  18:  End Module

3. Receive data in MVC controller without model (by FormCollection or by Name).

The first way to receive simple parameters without model is using FormCollection class. There are some example in my site with this method.

The second way to receive simple paramers without model is using name of parameters exactly as it named in View (for example - UserID as string, Password as string). Advantage of this type to receive parameters is automatically type casting. This is template of new MVC code controller created by Visual Studio.

Example of this approach you may see in end of page:

4. Receive data in MVC with model.

A good example of receive simple parameters with model you can see in page StudentsController2.vb (Contoso University). If you create controller by scafford template, you can see all of class of your project and you can select class for template for Model what using to thansfer data between view and controller.



But this is extremally simple example. Go ahead to real code.

Firstly, if you using model no sense take simple html-tag in form like <label> or <input>. All MVC concept is buitling across various attributes like Data Annotations, Validation Atributes and other. Therefore first point to take advantage for this way to transfer data between controller and view is creation Model and second point is using special ASP.NET tag in View, like @Html.TextAreaFor and @Html.ValidationMessageFor, which automatically process this attributes for various purposes

Because I use in my project Model first concept, I have no right directly add needed attributes in DB definition (at common this is standard MVVM concept).



Therefore I prepare additional View model with needed attributes.


   1:  Imports System.ComponentModel.DataAnnotations
   2:   
   3:  Public Class ViewResumeModel
   4:   
   5:      <Required(ErrorMessage:="Skills is mandatory.")>
   6:      <StringLength(1000)>
   7:      Public Property Skills As String
   8:   
   9:      <Required(ErrorMessage:="Title is mandatory.")>
  10:      <Display(Name:="Title of your bean", Prompt:="Title of your bean", Description:="No more than 100 chars")>
  11:      <StringLength(100)>
  12:      Public Property Title As String
  13:   
  14:      <DataType(DataType.Upload)>
  15:      <Display(Name:="Upload PDF files with your resume (if necessary)")>
  16:      Public Property InputPDFFile As HttpPostedFileBase
  17:   
  18:      <DataType(DataType.Upload)>
  19:      <Display(Name:="Upload your Avatar (if necessary)")>
  20:      Public Property InputAvaFile As HttpPostedFileBase
  21:   
  22:      <Required(ErrorMessage:="Description is mandatory.")>
  23:      <Display(Name:="Enter description for customer.", Prompt:="Enter description for customer.", Description:="No more than 1000 chars.")>
  24:      <DataType(DataType.MultilineText)>
  25:      <StringLength(1000)>
  26:      Public Property ShortDescription As String
  27:   
  28:      <Required(ErrorMessage:="PublicContacts is mandatory.")>
  29:      <Display(Name:="Enter your public contacts for customer.", Prompt:="Enter your public contacts for customer.", Description:="Any your public contact in free form, No more than 100 chars.")>
  30:      <DataType(DataType.Text)>
  31:      <StringLength(100)>
  32:      Public Property PublicContacts As String
  33:   
  34:      <Display(Name:="Enter your email for Sign in to this site.", Prompt:="Enter your email for Sign in to this site.", Description:="We sent password to this email.")>
  35:      <DataType(DataType.EmailAddress)>
  36:      Public Property AdminContacts As String
  37:   
  38:  End Class

And change the view for this model:


   1:  @ModelType ViewResumeModel
   8:   
   9:  <div class="row">
  10:      @*<form role="form" name="resumeform" id="resumeform" method="post" enctype="multipart/form-data" action="/api/Upload/PostResumeData">*@
  11:      @Using (Html.BeginForm("PostResume", "Resume", FormMethod.Post, New With {.enctype = "multipart/form-data"}))
  12:          @Html.AntiForgeryToken()
  13:          @<div Class="col-md-1 panel1" style="border:none">
  14:          </div>
  15:          @Html.Partial("~/Views/Resume/PostSetSkillPanel.vbhtml")
  16:          @<div class="col-md-7 panel1">
  17:              <h2> Please fill all fields in your public resume </h2>
  18:              <div style="max-height: 750px; min-height:750px; overflow: auto;">
  19:                  <div class="form-group">
  20:                      @*<label for="Title"><span style="color:red">*</span> Title of your bean </label>
  21:                        <input class="form-control" id="title" name="title" placeholder="No more than 100 chars.">*@
  22:                      @Html.LabelFor(Function(m) m.Title)
  23:                      @Html.ValidationMessageFor(Function(m) m.Title, "", New With {.style = "color:red"})
  24:                      @Html.TextBoxFor(Function(m) m.Title, New With {.PlaceHolder = "No more than 100 chars.", .Style = "width:95%;"})
  25:                  </div>
  26:                  <div Class="form-group">
  27:                      @*<label for="InputPDFFile">Upload PDF files with your resume</label>
  28:                        <input type="file" class="form-control-file" id="InputPDFFile" name="InputPDFFile">*@
  29:                      @Html.LabelFor(Function(m) m.InputPDFFile)
  30:                      @Html.TextBoxFor(Function(m) m.InputPDFFile, New With {.type = "file", .Style = "width:95%;"})
  31:                      <p class="help-block">This pdf files not will be parsed or changed.</p>
  32:                  </div>
  33:                  <div class="form-group">
  34:                      @*<label for="InputAvaFile">Upload your Avatar (if necessary)</label>
  35:                        <input type="file" class="form-control-file" id="InputAvaFile" name="InputAvaFile">*@
  36:                      @Html.LabelFor(Function(m) m.InputAvaFile)
  37:                      @Html.TextBoxFor(Function(m) m.InputAvaFile, New With {.type = "file", .Style = "width:95%;"})
  38:                      <p class="help-block">Will be reduced to 100x100 px</p>
  39:                  </div>
  40:                  <div class="form-group">
  41:                      @*<label for="ShortDescription"><span style="color:red">*</span> Enter description for customer </label>
  42:                        <textarea class="form-control" id="ShortDescription" rows="7" placeholder="No more than 1000 chars." name="ShortDescription"></textarea>*@
  43:                      @Html.LabelFor(Function(m) m.ShortDescription)
  44:                      @Html.ValidationMessageFor(Function(m) m.ShortDescription, "", New With {.style = "color:red"})
  45:                      @Html.TextAreaFor(Function(m) m.ShortDescription, New With {.rows = "7", .PlaceHolder = "No more than 1000 chars.", .Style = "width:95%;"})
  46:                  </div>
  47:                  <div class="form-group">
  48:                      @*<label for="PublicContacts"><span style="color:red">*</span> Enter your public contacts for customer </label>
  49:                        <input class="form-control" id="PublicContacts" placeholder="Any your public contact in free form, No more than 100 chars." name="PublicContacts">*@
  50:                      @Html.LabelFor(Function(m) m.PublicContacts)
  51:                      @Html.ValidationMessageFor(Function(m) m.PublicContacts, "", New With {.style = "color:red"})
  52:                      @Html.TextBoxFor(Function(m) m.PublicContacts, New With {.PlaceHolder = "Any your public contact in free form, No more than 100 chars.", .Style = "width:95%;"})
  53:                  </div>
  54:                  <div class="form-group">
  55:                      @*<label for="AdminContacts">Enter your email for Sign in to this site. </label>
  56:                        <input type="email" class="form-control" id="AdminContacts" placeholder="We sent password to this email." name="AdminContacts">*@
  57:                      @Html.LabelFor(Function(m) m.AdminContacts)
  58:                      @Html.ValidationMessageFor(Function(m) m.AdminContacts, "", New With {.style = "color:red"})
  59:                      @Html.TextBoxFor(Function(m) m.AdminContacts, New With {.PlaceHolder = "We sent password to this email.", .Style = "width:200px;"})
  60:                      <span style="color:red">*</span> or <br />
  61:                      <label for="Publiccontacts">Sign In using another account</label>
  62:                      <a class="oauth" alt="Sign in using Github" title="Sign in using Github" href="/script/Membership/OAuthLogOn.aspx?auth=GitHub"><img src="/Images/octicons_github-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  63:                      <a class="oauth" alt="Sign in using Linkedin" title="Sign in using Linkedin" href="/script/Membership/OAuthLogOn.aspx?auth=LinkedIn"><img src="/Images/linkedin-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  64:                      <a class="oauth" alt="Sign in using Facebook" title="Sign in using Facebook" href="/script/Membership/OAuthLogOn.aspx?auth=Facebook"><img src="/Images/facebook-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  65:                      <a class="oauth" alt="Sign in using Google" title="Sign in using Google" href="/script/Membership/OAuthLogOn.aspx?auth=Google"><img src="/Images/google-plus-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  66:                      <a class="oauth" alt="Sign in using Microsoft" title="Sign in using Microsoft" href="/script/Membership/OAuthLogOn.aspx?auth=Microsoft"><img src="/Images/microsoft-lg.png" style="vertical-align:middle;padding-right:3px;border:0;"></a>
  67:                  </div>
  68:                  <button id="PostResume" name="PostResume" type="submit" class="btn btn-primary">Post Resume</button>
  69:                  @Html.ValidationSummary(True, "", New With {.style = "color:red"})
  70:                  <div style="color:red">@ViewBag.Errormessage</div>
  71:              </div>
  72:          </div>
  73:      End Using
  74:      @*</form>*@
  75:  </div>
  76:   
  77:  <script src="~/Scripts/jquery.validate.min.js"></script>
  78:  <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

And after that I have succesfully receive model in MVC comtroller:



5. Custom model provider.

If we have more complex model (you need calculation fields for example or filter it or other prepare) we can opportunity to create own model from simple form fields. Firstly we need prepare special model you need for. In this example I prepare model with name ViewResumeModel2 that has only one difference to model above - instead string in field "skills" it transfer filtered list of string.



Of cource, need to change type of model in controller and view.



My code of special custom model binder is look these.


   1:  Public Class СustomModelBinder
   2:      Inherits DefaultModelBinder
   3:   
   4:      Public Overrides Function BindModel(controllerContext As ControllerContext, bindingContext As ModelBindingContext) As Object
   5:          Select Case bindingContext.ModelType
   6:              Case GetType(ViewResumeModel2)
   7:                  Dim Request As HttpRequestBase = controllerContext.HttpContext.Request
   8:                  Dim SkillArr() As String = Request.Form("skills").Split(":")
   9:                  Return New ViewResumeModel2 With {
  10:                          .Title = Request.Form("Title"),
  11:                          .ShortDescription = Request.Form("ShortDescription"),
  12:                          .PublicContacts = Request.Form("PublicContacts"),
  13:                          .AdminContacts = Request.Form("AdminContacts"),
  14:                          .InputAvaFile = Request.Files("InputAvaFile"),
  15:                          .InputPDFFile = Request.Files("InputPDFFile"),
  16:                          .Skills = (SkillArr.ToList.Where(Function(x) Not String.IsNullOrEmpty(x))).ToList
  17:                  }
  18:              Case Else
  19:                  Return MyBase.BindModel(controllerContext, bindingContext)
  20:          End Select
  21:      End Function
  22:   
  23:  End Class

And in the last step we need to register our custom model bulder on start site procedures.



And this schema working perfectly:





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19
Link to this page: http://www.vb-net.com/RequestParameters/index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <MAIL ME>  <ABOUT ME>  < THANKS ME>