.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Action method returning an ActionResult used in a Action method

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

Hell all,

I have the Index action method calling a method that itself is an action method.

Example :

public ActionResult Index()
   //do stuff
   ActionResult result = MethodB();
   // ?? what to return here ??

public ActionResult MethodB()
   //do stuff

  return View("Index);

What to do in this case ?

View Complete Post

More Related Resource Links

Sending JSON Array to an ASP.NET MVC Action Method Argument


 <input type = "submit" onclick = "savePayment()"  value = "Test"/>

    <script type="text/javascript">
        function savePayment() {
            //Creating some test data
            var lineItems = new Object();
            lineItems.Entrys = new Array();
            lineItems.Entrys[0] = new Object({ Name: "Dung", Age: "21"});
            lineItems.Entrys[1] = new Object({ Name: "An", Age: "25" });

            //Posting them to server with ajax
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '<%=Url.Action("TestArray", "Json") %>',
                dataType: 'json',
                data: $.toJSON(lineItems),
                success: function (result) {
                    if (result) {
                    else {

view the modelstate errors in action method


for debugging purposes, how do I see the ModelState errors from code in the action method?  ModelState.IsValid returns false. I want to copy the error messages to a variable so I can display them in the debugger.



passing values to object properties of action method parameter


I have an action method that accepts a single parm.

That parm is an object with multiple properties. MVC correctly maps values from the querystring
to properties in the parm object by matching property name to querystring value name. 
Problem is, properties in the action method parm object which are themselves objects with
properties, are not assigned their matching values from the querystring. The class object has a
constructor which accepts a single string parameter.

How do I assign to properties of an action method parameter which are themselves class objects?



                <%: Html.ActionLink("Edit", "ProductMasterEdit", 
                       new { ProdKey=item.ProductKey.Value, 
                       ProductKey = item.ProductKey.Value })%> 

    public ViewResult ProductMasterEdit(ProductMaster Item)

  public partial class ProductMaster

    public ProductKey ProductKey
      get { return new ProductKey(this.ProdKey); }
      set { this.ProdKey = value.Value; }


jQuery post to an action method



I hope this is the right section to post this, as it does seem to be an MVC related issue. I'm trying to use the jQuery.post() function to post an object to an action method, but for some reason the nested objects aren't initialised properly when they're received by the action method.

Here's my javascript code:

var data = {
    Id: 10,
    User: {
        Id: 5
$.post("/Home/SaveCompany", data, function (data) {

And my action method:

public ActionResult SaveCompany(Company company)
    if (company.Id > 0) {
    } else {
    return Json(new { id = company.Id });

company.Id has a value of 10, but company.User.Id is 0. Any ideas what I'm doing wrong? I've not named any properties incorrectly, by the way.


Action method taking model object



I've an action method like the below:


public void Edit(Movie movie)



Movie has fields Id, Name. View is displaying name only in textbox. When button is clicked, the above action method's movie is populates with the updated name value but Id is 0, actually that record's id is 4. Thatswhy my updating of record is not working. Why MVC is putting 0 into id?


passing data from a DropDownListFor to Action method in MVC3 (Razor)


I have two questions regarding passing the selection of a dropdownlist to an action method in an MVC controller:


1. What are the options for actually passing the selection back to the action method as a parameter?  The only thing I've been able to get to work is to name the parameter and the select list the same.  For example, my action method looks like:

        public ActionResult Example(int? FeatureId)

// do something with FeatureId
            return View(someobject);

and the static HTML list looks like:


<select name="featureId1">

2.  How can I use an extension method to name the select list appropriately?  I've been trying to do it with the htmlAttributes method but I find that this only works on the id, not the name.  E.g.:



@Html.DropDownListFor(x => x.objects, new SelectList(Model.objects, "FeatureId", "FeatureName"), new { @id = "FeatureId", @name = "FeatureId" })







Returning Images from an ACTION


Hi Guys!

I'm working in a MVC application and I get stuck on this:

I'm working on a kind of file manager. I want to upload files (Images) and then, show those files.

I made a control that upload the file and renamed using a GUID. I get track of the properties of the file, i.e. content type, original name, etc.

Until here, everything is working perfect.

The second part is to show the file.

Let's use Images as example. I upload a JPG.  To show it, I want a controller/Action that return the image.


And use it like this:

<img src="/Images/getImage/5" />

"Image" represents the controller and "getImage" the Action.

5 represents the identification of the file.


Is this is possible??

I read almost every post, blog, book, whatever you can imagine and didn't find an example of this. There are thousands on how to upload the file, but nothing on showing it.

The must similar example I get is this:


Works like a charm. but is for displaying images stored in a database. I really try hard to figure out how to modify it to s

how can i return 401 error from a method return ActionResult?


how can i return   401 error from a method return ActionResult?

Returning reference value from AJAX web method call on JQuery


I got this flag that I am checking for authenticated signed in users:


    <script type="text/javascript">
        $(document).ready(function () {
            $('#test').click(function () {

        function flag() {
            var _flag = "False";

Web method called from JavaScript not returning correct type


Hello all-

I have a web method written in VB.Net, coded as follows:

<OperationContract()> _
        Public Function HowManyExportsLeft(ByVal userId As Integer) As Boolean
            _UserId = userId
            Dim MaxExports As Integer = Me.UserSettings.ExportSettings.ExcelExportSettings.MaximumNumberOfExports
            Dim MyExports As Integer = Me.UserSettings.ExportSettings.ExcelExportSettings.MyExportCount
            Dim returnValue As Integer
            If MaxExports = Integer.MaxValue Then
                returnValue = 999
                returnValue = MaxExports - MyExports
            End If
            Return returnValue
        End Function

Now, on the ClientClick method of an asp:Button, I call the following method :

function CheckExportsRemaining() {
    var hdnUserId = $get(CalcResults.Controls.hdnUserId);
    Services.Common.HowManyExportsLeft(hdnUserId.value, ExportCount_complete);

Which of course on success calls this callback method:

function ExportCount_complete(result) {
    if (result <= 3) {
        eACommonDialog.ShowDialog(getURLString(aspxSiteUrl, 'TrialExports.aspx?exportsRemaining=' + result), 420, 215, '', 75, false, true, '', false

HELP: Creating an ActionResult method to display a particular database record using Entity Framework


Hi All,

I have an ActionResult method that displays records from a database table (below):

namespace STD.Controllers
    public class StudentController: Controller
        StudentEntities stud;
        public StudentController()
        stud= new StudentEntities ();


        public ActionResult Index()
            ViewData.Model = stud.StudentTable.ToList();
            return View();


I want to design a method "ActionResult Student()" that accepts "Student ID" as a parameter and displays record for that particular student only.

What do I need to do to make this happen? Could anyone please help me with this?

Thanks in advance


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

pass value from textbox to action, formcollection best way here?


Hi I'm building a e-commerce store and on quantity of product I'm going with a textbox. I thought I would ask how would you do this? a viewmodel to use a strongly typed textbox or just get the value of the textbox from the formscollection passed in to the action?

Thanks for any input

Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Using CreateNewUserWizard SendingMail method to email me, not applicatnt.


I have staff area of my site I am protecting with forms authentication using c# and .Net 4.0. What I want to do is let the staff members register on the site but instead of the confermation email being sent to them I want it sent to me so I can go in and approve it. I have been trying to use the SendingMail method  but can not figure out how to get it to email me instead of the person that registered. I have searched around this site and find many topics on the SendingMail method but none seem to properly address my issue. Can anyone help me out?

statement cannot appear outside of a method body


hi all,

  i am posting my vb.net problem .plz tell me how to resolve this :-

Dim conn As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    'Dim mysqlconnection As New SqlConnection(conn)
    'If mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();
    'Dim mySqlcommand As New SqlCommand("select CategoryId,CategoryName from Categories", mysqlconnection)
    'Dim mySqlDataAdapter As New SqlDataAdapter(mySqlcommand)
    'Dim mydataSet As New DataSet()

    'if mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();

i m getting 5 errors in this code

declaration expected in mySqlDataAdapter.Fill method; Gridview1.DataSource=ds; Gridview1.DataBind();

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend