Click here to Skip to main content
13,092,725 members (64,619 online)
Rate this:
Please Sign up or sign in to vote.
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcVoucher.Models;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace MvcVoucher.Controllers
    public class HeaderController : Controller
               public ActionResult HeaderView()
            Header1Controller obj = new Header1Controller();
           SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MYDATA"].ConnectionString);
            DataSet ds = new DataSet();
            string strSelectCmd = "SELECT ([empno] +'-'+ [name]) as[empname],(PA +'-'+ PATXT) as pa,(PSA +'-'+ PSATXT) as [psa],OU,(CO_CODE +'-'+ CO_TXT) as [Companycode],PLAN1,CURRENCY  from dbo.zemp_tbl_rohit WHERE empno = '00019904'";
            SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, con);
            obj.PA = Convert.ToString(ds.Tables[0].Rows[0][1]);
            obj.NIITianCode = Convert.ToString(ds.Tables[0].Rows[0][0]);
            obj.OU = Convert.ToString(ds.Tables[0].Rows[0][3]);
            obj.PSA = Convert.ToString(ds.Tables[0].Rows[0][2]);
            obj.CompanyCode = Convert.ToString(ds.Tables[0].Rows[0][4]);
            obj.Currency = Convert.ToString(ds.Tables[0].Rows[0][6]);
            obj.Plan = Convert.ToString(ds.Tables[0].Rows[0][5]);
            ViewBag.message = "hello";
            ViewData.Model = obj;
            return View(ViewData.Model);

Question : I want to use this actionresult headerview() in one more view like a user control , so how to pass a reference of this in another view.When i use @renderpage("~view/Headerhtml.cshtm"l) in a different viewthen it gives a null reference error because in that view there is no ActionResult HeaderView(). Please help
Posted 5-Sep-12 19:13pm
Updated 5-Sep-12 19:16pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100