Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Ajax Form URL from List<ViewModel>

Ajax Form URL from List<ViewModel>

Scheduled Pinned Locked Moved ASP.NET
htmlcssdatabasedata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eddieangel
    wrote on last edited by
    #1

    My page has a model type of List. I am looping through that list and generating a form for each item. The items are all available reports, some of which accept parameters, some don't. As such, I decided to build a form for each one and handle the parameter processing on the controller end. Here is what the code looks like, sorta:

    @foreach(ViewModels.ReportViewModel item in Model) {
    * class="k-state-active"}}>
    class="k-link k-state-selected"}}>@item.name

                        @using (Ajax.BeginForm("Queue","Reporting",options))
                        {
                            @Html.HiddenFor(t => item.id)
                            @Html.Hidden("id",item.id)
                            foreach(var parameter in item.parameters) {
                                
    
                                    @Html.Label(parameter.displayName)
                                
    
                                
    
                                    @Html.EditorFor(p => parameter.name, "ECR")
                                
    
                            }
                            
    
                                <input type="submit" class="k-button k-button-icontext k-grid-select" style = "margin-left:255px;width:50px" id="submit" name="submit" value="Submit" />
                            
    
                        }
                    
    
                
        i++;
        }
    

    And the controller code looks like this:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Queue(ReportViewModel vm)
    {
    ReportQueue item = new ReportQueue
    {
    reportId = vm.id,
    userId = 2,
    statusId = 0,
    reportParams = null,
    datestamp = DateTime.Now
    };
    _uw.ReportQueueRepository.Insert(item);
    _uw.Save();

            return RedirectToAction("Index", new { id = vm.claimId });
        }
    

    The rendered form markup looks ok (action: /Reporting/Queue) but it is not hitting the action on the controller but is actually making a mess. Firebug shows it trying to process an Ajax request for data (Which is expected as the parameter.name triggers an editor template) but it is appending /Queue onto the Ajax request. What gives

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups