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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:16:23+00:00 2026-05-23T01:16:23+00:00

I have a problem in passing a value from controller to view In controller,

  • 0

I have a problem in passing a value from controller to view

In controller, In the edit method

    public ActionResult Edit( FormCollection form)
        {
        var id = Int32.Parse(form["CustomerServiceMappingID"]);

        var datacontext = new ServicesDataContext();
        var serviceToUpdate = datacontext.Mapings.First(m => m.CustomerServiceMappingID    == id);
        TryUpdateModel(serviceToUpdate, new string[] { "CustomerID", "ServiceID", "Status" }, form.ToValueProvider());

        if (ModelState.IsValid)
        {
            try
            {
                var qw = (from m in datacontext.Mapings
                          where id == m.CustomerServiceMappingID
                          select m.CustomerID).First();
                ViewData["CustomerID"] = qw;
                datacontext.SubmitChanges();
                //return Redirect("/Customerservice/Index/qw");
                return RedirectToAction("Index", new { id = qw });
            }
            catch{
                }
        }

        return View(serviceToUpdate);
    }

Now in edit’s view , I used this

                           @Html.Encode(ViewData["CustomerID"])

This is my Index method

    public ActionResult Index(int id)
    {

        var dc = new ServicesDataContext();
        var query = (from m in dc.Mapings
                   where m.CustomerID == id
                    select m);
       // var a = dc.Customers.First(m => m.CustomerId == id);
       // ViewData.Model = a;
       // return View();
        return View(query);
    }

But the customerID on the page turns to be null.. Can u let me know if this procedure is correct?

  • 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-23T01:16:23+00:00Added an answer on May 23, 2026 at 1:16 am

    You don’t need to requery the id. Just use the id directly:

    if (ModelState.IsValid)
    {
      datacontext.SubmitChanges();
      //return Redirect("/Customerservice/Index/qw");
      return RedirectToAction("Index", new { id = id});
    }
    

    Since you are redirecting the ViewData[“CustomerID”] will be lost.
    However the id in your Index method should be valid.
    If your Index View requires the ViewData[“CustomerID”] set it in your Index action:

    public ActionResult Index(int id)
    {
      ViewData["CustomerID"] = id;
      //....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem in passing a value from JS to PHP so that
My problem is similar to Django Passing Custom Form Parameters to Formset Ive have
I am having a problem with views. I have a view and am passing
I have problem on passing jquery variable on codeigniter controller. actually i want to
I have tried to use the following code to passing value back from the
I have a problem of passing data from one textarea to another textarea on
I currently have a method in my controller which accepts a form collection, saves
I have a problem with passing arguments from the NAnt style task to a
I'm experimenting with WCF Services, and have come across a problem with passing Interfaces.
In php, we have number_format() . Passing it a value such as: number_format(3.00 *

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.