Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MVC3 Razor
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 5-Sep-12 20:13pm
drstylo571
Edited 5-Sep-12 20:16pm
v4

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



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2014
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