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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:20:19+00:00 2026-06-13T15:20:19+00:00

I have a controller HomeController with the following action method : [HttpPost] public ActionResult

  • 0

I have a controller HomeController with the following action method:

[HttpPost] 
public ActionResult DisplayData(MyViewModel myViewModel)
{
   // Do something with myViewModel           
}

The ViewModel:

public class MyViewModel
{
    public string Name { get; set; }
    public string Surname { get; set; }
    public bool IsPeriod { get; set; }
}

And the following View

@model AppName.ViewModels.MyViewModel

@{ Html.RenderPartial("MyPartialView", Model);  }

<img src="@Url.Action("DisplayData", "Home", new { myViewModel = Model })" alt="Image" />

I use the Url.Action how it is described here but what I get in the DisplayData action method is null. In the source code I got:

<img src="/Home/DisplayData?filters=AppName.ViewModels.MyViewModel" alt="Image" />

so it is passing actually the type instead of the values.

The ViewModel instead is correctly passed to the partial view. What am I doing wrong?

  • 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-13T15:20:21+00:00Added an answer on June 13, 2026 at 3:20 pm

    I usually add the following to my model:

    public class MyViewModel
    {
        public string Name { get; set; }
        public string Surname { get; set; }
        public bool IsPeriod { get; set; }
    
        public RouteValueDictionary RouteValues
        {
            get
            {
                var rvd = new RouteValueDictionary();
                rvd["name"] = Name;
                rvd["surname"] = Surname;
                rvd["isPeriod"] = IsPeriod;
                return rvd;
            }
        }
    }
    

    Then you can simply use the RouteValues property in your Url.Action() call.

    <img src="@Url.Action("DisplayData", "Home", Model.RouteValues)" alt="Image" />
    

    Or if your prefer less (explicit) code, ignore the model changes and simply do this:

    <img src="@Url.Action("DisplayData", "Home", new RouteValueDictionary(Model)" alt="Image" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following action: public class HomeController : Controller { public ActionResult Index(int?
Have Controller: public class MyController : Controller { [HttpGet] public ActionResult MyAction(int iMode, string
I have the following controller: public sealed class SomeController : Controller { public ActionResult
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
I have a the following controller containing one action with a single parameter: public
I have Controller: [MySite]\Controllers\DistributionTools\TrackingChannelsController.cs [HttpPost] public void InitTcFirstPageView() { var model = new TcFirstPageModel
With the following code (using Moq 4.0.10501.6): HomeController controller = new HomeController(); ActionResult result
In an ASP.NET MVC3 project, I have 2 controllers: one is HomeController.cs public class
I have the following code in my HomeController's Index action, and the code below
I have controller users . In this controller I have action account which is

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.