Click here to Skip to main content
15,918,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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();
            con.Open();
            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);
            da.Fill(ds);

            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";

            con.Close();

            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
Updated 5-Sep-12 19:16pm
v4

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900