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

  • Home
  • SEARCH
  • 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 3982552
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:32:28+00:00 2026-05-20T05:32:28+00:00

I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>

  • 0

I have my main view like this:

<%@ Page Title=”” Language=”C#” MasterPageFile=”~/Views/Shared/Site.Master” Inherits=”System.Web.Mvc.ViewPage” %>

Index

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>

<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>

<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

<h2>
    Index</h2>

<script type="text/javascript">
    $(function() {
        $('#mylink').click(function() {
            $('#resultpartial1').load(this.href);
            return false;
        });
    });

    $(function() {
        $('#mysecondlink').click(function() {
            $('#resultpartial1').load(this.href, { id: 123 });
            return false;
        });
    });
</script>

<%= Html.ActionLink("click me","Partial1","Foo",new MyViewModel { Foo = "123" , Bar="456" },new { id = "mylink" }) %>
<%= Html.ActionLink("click me second link","Partial2", "Foo", new { id = "123" }, new { id = "mysecondlink" }

) %>

and controller like this:

public class FooController : Controller
{
    //
    // GET: /Foo/

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Partial1(string id)
    {
        // TODO: use the id to fetch the model from somewhere
        MyViewModel model = new MyViewModel { Bar = "a", Foo = "1" };
        return View(model);
    }

    public ActionResult Partial2(string id)
    {
        // TODO: use the id to fetch the model from somewhere
        MyViewModel model = new MyViewModel { Bar = "b", Foo = "2" };
        return View(model);
    }
}

}

and partial views like this :

<%@ Control Language=”C#” Inherits=”System.Web.Mvc.ViewUserControl” %>

Foo:

Bar:

<%@ Control Language=”C#” Inherits=”System.Web.Mvc.ViewUserControl” %>

Foo:

Bar:

I am always getting values set by controller actions. I want to set values in view and pass to partial view. How can I do this ?

  • 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-20T05:32:29+00:00Added an answer on May 20, 2026 at 5:32 am

    Assuming you have a view model

    public class MyViewModel
    {
        public string Foo { get; set; }
        public string Bar { get; set; }
    }
    

    and a controller:

    public class FooController: Controller
    {
        public ActionResult Partial1(string id)
        {
            // TODO: use the id to fetch the model from somewhere
            MyViewModel model = ...
            return View(model);
        }
    
        public ActionResult Partial2(string id)
        {
            // TODO: use the id to fetch the model from somewhere
            SomeOtherViewModel model = ...
            return View(model);
        }
    
    }
    

    a corresponding partial view:

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.MyViewModel>" 
    %>
    <div>Foo: <%= Html.DisplayFor(x => x.Foo) %></div>
    <div>Bar: <%= Html.DisplayFor(x => x.Bar) %></div>
    

    and finally in your main view you could have a link:

    <%= Html.ActionLink(
        "click me", 
        "Partial1", 
        "Foo", 
        new { id = "123" }, 
        new { id = "mylink" }
    ) %>
    <div id="resultpartial1" />
    

    which could be AJAXified:

    $(function() {
        $('#mylink').click(function() {
            $('#resultpartial1').load(this.href);
            return false;
        });
    });
    

    Now of course if the id parameter is known only with javascript you could do this:

    <%= Html.ActionLink(
        "click me", 
        "Partial1", 
        "Foo", 
        null, 
        new { id = "mylink" }
    ) %>
    

    and then:

    $(function() {
        $('#mylink').click(function() {
            $('#resultpartial1').load(this.href, { id: 123 });
            return false;
        });
    });
    

    UPDATE:

    And for the second link:

    <%= Html.ActionLink(
        "click me second link", 
        "Partial2", 
        "Foo", 
        new { id = "123" }, 
        new { id = "mysecondlink" }
    ) %>
    <div id="resultpartial2" />
    

    and then:

    $(function() {
        $('#mysecondlink').click(function() {
            $('#resultpartial2').load(this.href, { id: 123 });
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view defined for a url 'site/main/'. I would like to be
In the main view i have this function public function lang($file, $language){ require 'languages/'.$language.'/'.
I have an application that it's main page is organized like this: Grid (LayoutRoot)
I have a view file like this : <html> <head> <meta name=layout content=main />
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
Excuse me if this is slightly newbie. I have the main view located @
At the present time I have my main page title set to the page
I have a main view and the URL for this view has a Action/Controller/Area
I have the normal pagination like this in my view: paginator = Paginator(book_list, 100)
I have added navigation controller into my appication in didFinishLaunchingWithOptions like this LoginViewController *mainView

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.