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 5989315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:05:02+00:00 2026-05-22T23:05:02+00:00

I need some information here. I am totally new at MVC therefore for you

  • 0

I need some information here. I am totally new at MVC therefore for you guys, I think it will be an easy question to answer. I have the following structure:

Controller.cs

Public ActionResult PageMain() {
     return View(); // this is the main page I'm working with
}

[ChildActionOnly]
Public PartialViewResult Partial1(string tablename) {
      //Some code to construct datatable according to the url parameter
      return PartialView("Partial1", DataTable);
}

Public ActionResult FormAction(string tablename, FormCollection formvalues) {
      //Here I send the values to the model in which I have a public void
      //that updates the database -> I'm not using Linq at this phase because 
      //both the tables and fields are dynamic
      //I execute the code in a try and catch statement

      try 
      {
          //some code
          Response.Redirect("url to PageMain");
      } 
      catch (Exception ex) {
          ModelState.AddModelError("Error", ex);
          Return View("PageMain", ex); 
          // actually, here I'd like to send the exception error
          // to the partialview which renders the error as its model but 
          // but I don't know how since if I use return PartialView() 
          // then only the partial view will be displayed, not the whole page
      }
}

Finally, in the PageMain View I have:

//Some initial code with the form that posts value to FormAction
@Html.RenderPartial("Partial1") //this is the partial which shows error 
                                //it is only displayed when the form is posted
                                //and there is an error

Okay, now, my questions are: Is such a structure valid (here by valid I mean if it is well structured or there is a better way)? and how can I reach the Exception in the ModelState.AddModelError() method in the Partial View ‘Partial1’?

In case you are confused, to sum up:

  • In PageMain, there is a table constructed in accordance with the url-parameter. Actually,
    it is constructed in another partialview but displayed in the PageMain
  • When I edit the table, the form redirects me to FormAction, which the codes are executed
    to edit the database
  • Finally, if there is error, user remains in the FormAction, but in this page the View used is still PageMain, I have not a different view for this page since it would be like constructing the same page twice. I mean, only to include a partialview which shows the errors I did not want to create another view. Instead, I am trying to make visible the partial view with some if – else logic only in case of some errors
  • 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-05-22T23:05:03+00:00Added an answer on May 22, 2026 at 11:05 pm

    A few things I would change here

    First, here:

     Response.Redirect("url to PageMain");      
    

    You want to instead return a

    RedirectToAction("PageMain") 
    

    second – make Pagemain only valid for get requests by using the HttpGet attribute.

    [HttpGet]
    public actionResult PageMain() 
    {     
       return View(); 
    // this is the main page I'm working with
    }
    

    Third – make this HttpPost

    [HttpPost]
    Public ActionResult FormAction(string tablename, FormCollection formvalues) 
    

    Fourth –
    Usually you will see people have the GET method and POST method have the same name, and one is marked HttpGet and one HttpPost accepting of course different parameter types.

    Fifth –
    What I would recommend is your view is a strongly typed view not based around DataTable but your own class – say named “Customer”
    at the top of your view you know its strongly typed when you see something like (for a list of customers)

    @model IEnumerable<Customer>
    

    When you do this, your FormAction method can automatically take an object of type Customer – the Model Binder in MVC automatically matches your form values to names in this object and sets the property values. This is one of the great features with MVC. So your method would become:

    Public ActionResult FormAction(Customer customer) 
    

    and now you have a customer object to deal with.

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

Sidebar

Related Questions

I need some help extracting the following bits of information using regular expressions. Here
Im just starting with localization today and need some information. I have a project
I have a JInternalFrame and I need to get some Information from user (a
I have a div inside form something like <form> <div> showing some information here
Disclaimer: i have searched genericly (Google) and here for some information on this topic,
I have one Form, that opens another one. The user writes some information here.
I'm new to Java and I need some advice/information on how to debug my
I need to send some information on a VxWorks message queue. The information to
I need to present some information in a table view where some information is
I need to show some information in a graph, the data is held in

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.