Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:30:32+00:00 2026-06-05T17:30:32+00:00

I’m having issues with my MVC3 vb.net application. When I try to post the

  • 0

I’m having issues with my MVC3 vb.net application. When I try to post the changes I’ve made to the controller, the model is not send to the controller.

I’ve tried to follow many posts like this one and this one, but I’m not sure of how to implement them in my application since my model did not send IEnumerable types.

At the end I only want that the model returns one value for each batch that is the value that I will save to the database.

When I post the model and try to send to the controller the page sends the following by post:

Client=2&Datacenters=20&BatchesForAssignation[0].CenterID=4&BatchesForAssignation[1].CenterID=20&BatchesForAssignation[1].DatacenterID=14...

But I don’t know how to convert this querystring to a BatchesForAssignation object, assign it to the model and send to the controller.

NOTE: The values for Client and Datacenters shown in the querystring are not used in the controller. I need the BatchesForAssignation[n].CenterID part.

Can you please point me to found a solution on this?

This are the objects that I’m using in my MVC application (code compacted):

Batch:

Public class Batch
    public property ID as integer
    public property CenterID as integer
    public property name as string
end class

Centers (This object just store all the list of centers that will be assigned to the Batch. The name is just to show the name in the drop down list):

Public class Center
    public property ID as integer
    public property name as string
end class

(There’s also a Batchlist and a Centerlist objects that acts as collections inherited from CollectionBase that stores all the Batch and Center objects. If you need the class definition please let me know but is pretty strightforward).

The model is as follows

Public class ProcessingModel
    public property BatchesForAssignation as BatchList
    public property Datacenters as CenterList
End class

The Controller is as follows:

<HttpGet()>
<Authorize()> _
Public Function AssignToDataCenters() As ActionResult
    Dim model As New ProcessingModel
    Dim BatchHandler As New BatchControl

    'This line will get the list of batches without datacenter
    model.BatchesForAssignation = BatchHandler.GetBatchesAvailable(ConnectionString)

    'This method will get the list of Datacenters available
    model.Datacenters=BatchHandler.GetDatacenters(ConnectionString)
    return View(model)
End Function

HttpPost (This is actually not working because the model returns an empty model):

<HttpPost()>
<Authorize()> _
Public Function AssignToDataCenters(ByVal Model as ProcessingModel) As ActionResult
    Dim BatchHandler As New BatchControl
    Dim SaveResult as Boolean=false

    'This line will get the list of batches without datacenter
    model.BatchesForAssignation = BatchHandler.GetBatchesAvailable(ConnectionString)

    'This method save the information returned by the model
    SaveResult=BatchHandler.UpdateBatches(model)

    ViewBag("Result")=SaveResult
    Return View(model)
End Function

The View is as follows (is a Strongly-typed view):

@ModelType MVCAdmin.ProcessingModel

@Code
    ViewData("Title") = "Assign Batches To centers"
End Code

@Using Html.BeginForm()
    @<table id="tblAvailableBatches">
        <thead>
            <tr>
                <th>Assign batch to:</th>
                <th>Name</th>
            </tr>
        </thead>
        <tbody>
            @code
                For i As Integer = 0 To Model.BatchesForAssignation.Count - 1
                    Dim a As Integer = i
                    @<tr>
                        <td>@Html.DropDownListFor(Function(m) m.BatchesForAssignation(a).CenterID, New SelectList(Model.Datacenters, "ID", "name", model.BatchesForAssignation(i).CenterID), " ")</td>
                        <td>@Model.BatchesForAssignation(i).name</td>
                    </tr>        
                Next
            End Code
        </tbody>
    </table>
    <input type="button" value="Apply changes" id="btnApply" />
End Using

Thanks in advance

UPDATE 2012-06-14:

After making some researh I found that I can parse the querystring in the controller using request.Form I can parse the results sent by the view. But the querystring keys are in the form BatchesForAssignation[0].CenterID,BatchesForAssignation[1].CenterID,BatchesForAssignation[2].CenterID and so on…

Is there’s a better way to do this “automagically” so that the model parses the querystring and sends the parsed object to the controller?

Again…Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:30:33+00:00Added an answer on June 5, 2026 at 5:30 pm

    After reviewing this question I’ve found that the best way to create the model and send it to the controller is creating a CustomModelBinder (from the IModelBinder Interface) and parsing the form’s querystring on the BindModel method using the controllerContext.HttpContext.Request.Form property. Something like this:

    Public Class ProcessingModelBinder
        implements IModelBinder
    
        public Function BindModel(controllerContext As System.Web.Mvc.ControllerContext, bindingContext As System.Web.Mvc.ModelBindingContext) As Object
            dim model as ProcessingModel = if(nothing.equals(bindingContext.Model),directcast(bindingContext.Model,directcast(DependencyResolver.Current.GetService(typeof(ProcessingModel))
            dim Keys as string()=controllerContext.HttpContext.Request.Form.AllKeys
    
            for each key in Keys
                'Fill the model required parameters
            Next
    
            return model
    End Function
    

    And finally register the new Model Builder in the global.asax file

    Sub Application_Start()
        AreaRegistration.RegisterAllAreas()
        ModelBinders.Binders.Add(typeof(ProcessingModel),New ProcessingModelBinder())
        RegisterGlobalFilters(GlobalFilters.Filters)
        RegisterRoutes(RouteTable.Routes)
    End Sub
    

    I hope that this helps someone

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.