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

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

Problem passing parameters to controller

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net

I have a problem with getting a parameter in my controller.
My url is: http://localhost:portnr/News/Details/43

My Global.asax:

    null, // Route name 
    "{controller}/{action}/{newsid}", // URL with parameters 
    new { controller = "News", action = "Details", newsid = "" } // Parameter defaults 

My controller code:

public class NewsController : Controller 
    public ActionResult Details(int? newsid) 
        //some code 

My controller is never getting the value out the url, how can i fix it ?
I don't want to use: /Details?newsid=43

View Complete Post

More Related Resource Links

Problem : Need to make COM InterOp at runtime using reflections Passing Pointers as parameters?

Hello, I need to make COM IntetrOp at runtime using reflections. My native COM Object's exposed methods have some parameters as pointers (DWORD*) and some double pointers (DWORD**) and some are user defined types(e.g SomeUDTType objSmeUDTType) and vice versa its pointer(i.e. SomeUDTType *pSomeUDTType). Now for dynamic method invocation, we have single option for passing parameters as array of object i.e object[] and filling this array statically. But I need to pass pointers and references and pointers to pointers. For now how can I be able to populate object array as mixed data of simple data types, pointers or references and pointers to pointers. Working Example: Native COM exposed method : STDMETHODIMP MyCallableMethod(DWORD *value_1,BSTR *bstrName,WESContext a_wesContex Translated by tlbimp.exe (COMInterop) UDTINIDLLib.RuntimeCallingClass.MyCallableMethod(ref uint, ref string, UDTINIDLLib Now calling these methods at runtime using reflection at runtime, See here :        Assembly asembly = Assembly.LoadFrom("E:\\UDTInIDL\\Debug\\UDTINIDLLib.dll");         Type[] types = asembly.GetTypes();         Type type = null;    //foreach (Type oType in types)         {             try      &nb

problem when passing data from view back to controller?


I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID,  which i dont want to be seen on page.

So I  removed every   Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc... from generated View source.

And because of this when Html.BeginForm() returns that object back to Controller  all values is there but UserID is lost??

If I leave Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine.

But I dont want to show UserID?

Where is the problem here?

                <%= Html.LabelFor(model => model.C__User_Id) %>

Problem Using Invoke and passing multiple byref parameters


I have code, shown below highly simplified that works all except for 1 thing: The variables being passed byRef get passed, but once modified in RecordData, they are never updated in the calling function. The calling function does not receive the updated data that is in the variables custid and amt. When debugging, I see the data in the else section of if me.invokerequired, but once it returns from the callback and is in the latter part of if me.invokerequired the data is missing.

How do I fix this?


Delegate Sub RecordDataCallback(ByRef custid As String, ByRef amt As Double)

Private Sub RecordData(ByRef custid As String, ByRef amt As Double)
    If Me.InvokeRequired Then

file not passing to controller


 I am getting an null referance on file, what am I doing wrong. 

<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
<%: Html.ValidationSummary(true) %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name="btnAdd" value="Add" />
<% Html.EndForm(); %>

controller code:

        public ActionResult AddMedia(Guid id, HttpPostedFileBase file, FormCollection collection)
            string mimeType = file.ContentType; //  Null Exception here ..

Passing Parameters through sub reports



I am trying to use a parameter field where there is a subreport in my main report but i keep getting the error "subreport cannot be shown" when running the report. Any ideas please.

p.s - I have just set the parameters the same in the subreport as the main report.



Passing report parameters by report viewer


I have 4 parameters in which 3 are passed in report and 1 is passed through report viewer. I have made a parameter in SSRS called CandidateId to which I want to pass the value. The code for report viewer is:

 intReportID = Convert.ToInt32(Request.QueryString["ReportID"
 CandId = Convert.ToString(Session["CandidateId"
lblReportName.Text = dtReport.Rows[0]["ReportName"
SSRSReportViewer.ShowCredentialPrompts =false

 SSRSReportViewer.ServerReport.ReportServerCredentials = new
SSRSReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.


 SSRSReportViewer.ServerReport.ReportServerUrl = new

SSRSReportViewer.ServerReport.ReportPath = dtReport.Rows[0]


 Microsoft.Reporting.WebForms.ReportParameter[] theparams = new

theparams[0] = new
, CandId);
theparams[0].Visible = false

Problem with Finder method with parameters



Could someone explain me how to provide some value to the parameters in a finder method. For exemple I know that the BDC list WP use this method. Is there a way to provide some value for those parameter at runtime? I really don't understand (even after some deep search on the web) where are the values for the parameters from and how we can connect to them. Even with C# code I can't find any information on how it work.

I don't want to define my parameters as filter in the ADF because then I will have this filter section in my BDC list WP (or is there a way to get rid of that?). Actually one of the parameter should be automatically calculated from a value in a SP list, the other parameter should be provided by my own filter web part.

Thank you for your help.

passing object values from server to client problem


I get a message that x_login is not declared.  I added Dim login as String = "123", but that didn't help.  What's the problem?

code behind....

Dim Login = "123"
x_login.Value = loginID


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<form id="simForm" runat="server" method='post' action='https://test.authorize.net/gateway/transact.dll'>
        <input id="HiddenValue" type="hidden" value="Initial Value" runat="server" />
        <input type='hidden' runat="server" name='x_login' id='x_login' />
        <input type='submit' runat="server" id='buttonLabel' />



Problem with passing an Image as binary through web service



I have a web service that is accessed by a windows forms application and receives updates like facility name, address, image etc. Everything works fine except the image data is not being passed to the windows app. I am saving the images in database on both sides, so when I pull it from the server I use the following code

if (!reader.IsDBNull(floorPlanOrdinal))

facility.FloorPlan = (byte[])reader["FloorPlan"];

I can see the facility.FloorPlan Dimentions as 103840 when I debug this method which means that the data is pulled from the database fine.

On the forms side though the dimentions become 0, all other values pass fine except this. Here is the facility property in the web service on server side.

using System;

using System

Preview Crystal Report from ASP.net without passing parameters


Hi Everyone,

Sorry couldn't think of any better Subject..

I am developing a User Reports Module using C#.Net using Visual Studio 2005. Basic purpose of this module is to allow user to be able to run their own Crystal Reports. i.e. if Users have their own Crystal Reports specific to their needs then we allow them to save them and view them from our user reports module.

So when user saves any report we save it on server and save the Physical path of that report in database. Now when user tries to view the report I get the location from database and load it. Which works ok. The issue now is those reports which have got parameters. 

I am not saving any information about parameters in their reports. So I do not have any information about Report Parameters.

This same application exists in VB6. What that VB application does is opens the Crystal Report and then Crystal report asks for needed parameters exactly as it will do if we try to open a crystal report using crystal report and preview it from there it asks for parameter values. 

How can I do that in C#.Net.

VB has got code like this

Global Appl As New CRAXDRT.Application

Problem passing custom object returned by the same webservice among two separate projects

I am running into casting issue with this scenario: 1. I made a custom object lets call it EmployeeObject.  2. The Employee object is wrapped in the EmployeeWebservice.  3. I have a client application project lets call it EmployeeClientApplication and a class library called DoSomeWorkClassLibrary.  Both EmployeeClientApplication and DoSomeWorkClassLibrary reference the EmployeeWebService and need to be able to pass the EmployeeObject back and forth.  4. The EmployeeClientApplication also references the DoSomeWorkClassLibrary. 5. The employeeObject in the EmployeeClientApplication becomes EmployeeClientApplication.EmployeeWebService.EmployeeObject. 6. The employeeObject in the DoSomeWorkClassLibrary becomes DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject. 7. The DoSomeWorkClassLibrary has a method called DoSomeWork that takes an EmployeeObject. When I try to pass employeeObject from EmployeeClientApplication to DoSomeWorkClassLibrary by doing something like this: DoSomeWorkClassLibrary.DoSomeWork(EmployeeClientApplication.EmployeeWebService.EmployeeObject), I am getting Unable to convert EmployeeClientApplication.EmployeeWebService.EmployeeObject to DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject.  I have searched high and low to fix this issue, I have tried changing the namespace of the reference.cs file of the webservice in

Help Passing Multiple Parameters Via a URL in SSRS 2008

Hello Everyone, I'm totally and completely confused as to how to pass multiple paramters through a URL.  Book Online is absolutely no help because they do not offer any examples of passing multiple paramters within a URL.  Instead, I get confused over RENDER and COMMAND and what should be repeated where with each paramter and on and on and on. Here's my URL: javascript:void(window.open('http://sereporting01.wdig.com/ReportServer?%2fDOL%2fTEST%2fDisney+Sell-Through&rs:Command=Render&SiteName=Disney,InsertionType=300 x 250,Context=ROS','_blank','resizable=yes,toolbar=0,menubar=0')) What happens is that JavaScript opens a new window but I get a "Reporting Services Error".  I'm assuming it's because my URL parameters are not correct.  Can someone please just give me the correct syntax so that I can get on with my work? I'm editing this post to add - I'm also confused as to how paramters are supposed to be passed through to a report when default paramters are set up in the report which i'm trying to open with the URL.  Should I remove the default paramaters from the report or...what? Again, BOL offers no help on this issue and it just seems to generate more questions.  Thanks!!  

Passing Multiple Parameters in NavigateURL Property of Hyperlink

In ASP.NET 3.5, is this the only way to pass Multiple Parameters in NavigateURL Property of Hyperlink ? What about using the HyperlinkField?<asp:TemplateField HeaderText="Form Name">    <ItemTemplate>        <asp:HyperLink ID="HyperLink2" runat="server"         NavigateUrl='<%# "~/Application/" + Eval("FormType") + ".aspx?FormID=" + Eval("FormID") %>'         Text='<%# Eval("FormName") %>'>                </asp:HyperLink>     </ItemTemplate></asp:TemplateField>

Performance problem when passing a "nullable parameter"

Say @startDate and @endDate are my datetime parameters. If users does not want to limit the @startDate for example, he/she sends a null value to @startDate. Same goes for @endDate (and any other parameter). What I like doing: Select * From MyTable Where MyTable.Date >= IsNull(@startDate, MyTable.Date) And MyTable.Date <= IsNull(@endDate, MyTable.Date) The above looks nice as far as coding but when I look at the execution plan I'm surprised to see the my clustered index (that has it's first column as "MyTable.Date") is not used. instead I get an index scan. More frustrating is that the following works with an index seek and is much faster: Select * From MyTable Where MyTable.Date >= @startDate And MyTable.Date <= @endDate So what should I do? am I doing something wrong? I don't want to use dynamic sql because it's generally slower and prone to sql injection (is dynamic sql my only choise)? I don't want to use "if statements" because then i'd have to rewrite my code several times (in this case three combinations but some of my procedures have up to 8 "nullable" parameters). Or maybe there is another way of implementing what I call here "nullable parameters". obviously I preformance is crucial. thanks, Dror

MDX problem (Amount value is getiing doubled when multiselecting dimension parameters)

Hello...I need some help with the MDX...basically the problem is the Amount value is getting doubled when I am selecting more than one parameter. Here is situation...suppose I select a parameter  lets say A from dimension Account Element Hierarchy then I get the Budget Amount as $100, now in my SSRS report I change the dimension parameter value to B and then I get the Budget Amount $200. Now I multiselect A and B and ideally I should get the Total Budget Amount as $100+$200=$300 but in place of that I get $600 I have captured the mdx below...Please let me know if you have an idea to fix this --The below MDX returns $100 for Budget Value SELECT   NON EMPTY { [Measures].[Budget Amt], [Measures].[Budget / RSF] } ON COLUMNS, NON   EMPTY { (DESCENDANTS([Account Hierarchy].[Account Hierarchy].[Level 02].ALLMEMBERS) ) } DIMENSION   PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME, PARENT_UNIQUE_NAME, LEVEL_NUMBER ON   ROWS FROM [Finance]   WHERE (STRTOSET("{[Account Element Hierarchy].[Account Element Hierarchy].&[1214|425|406|495|1209|421]}"),   STRTOMEMBER("[Date].[Year].&[2010]"),   STRTOMEMBER("[Budget Version].[Budget Version].&[Budget]"), [Account Hierarchy].[Account Hierarchy Type].&[2])   CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR,   FORMATTED

Problem with Parameters

I'm fairly new to this and appreciate any detailed info you're able to give. I have a report that has two datasets. One dataset queries for possible term code values which is then passed into the second dataset. If I execute the first dataset statement within the report builder, I receive an expected output. If I hard code a value into the "?" parameter location in the second dataset, I receive expected information. It doesn't, however, work correct when previewed. My data source is of the "Oracle" type. Executing the report in the Preview tab results in: An error has occurred during the report processing. Query execution failed for data set 'Banner_FU'. ORA-01036: illegal variable name/number.   What am I missing?   joe

Passing parameters from ASP.Net web page to SSRS report

I have a web page that displays some data.  The user first selects a date range on the web page and then can edit some data.  When they click a submit button, I want to run a report.  But I would like to pass the start date and end date values that the user already entered on the web page to the report.  Is this possible?  Can I use the value of a session variable in the report? Bob
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