3

How to use .cs Class DataFunctions Inside MVC Controller Classes

 3 years ago
source link: https://www.codesd.com/item/how-to-use-cs-class-datafunctions-inside-mvc-controller-classes.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to use .cs Class DataFunctions Inside MVC Controller Classes

advertisements

I have an asp.net web application, now i am trying to convert it to ASP.NET MVC. The problem is my old project has some .cs classes i, Example one class that handle all user data operations , one handle database operations , one will handle some priority properties like... I had included those classes in mvc Project , i had created a new Folder named Project_Class and copy all of my classes to it, my problem is how to access these classes in mvc controller class, how can i call a function of this class in mvc controller class.

I had include a sample .cs class structure below 

**class1.cs** 

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace xyz.abc
{
    public class AssignValues:SSS
    {
        Process Objdb;
        SqlCommand sqlcom;
        SqlConnection sqlcon;

        private int _EId;
        private int _CId;
        XmlDocument PXML, OutputXML;
        XmlElement Root, ParameterElement, InputParamIdNode, OperatorIdNode, OutputParamIdNode, OutputParamValueNode, ConditionStatusNode, ModeNode, InputTypeNode, OutputTypeNode, InputRegisterIdNode, InputRegisterHeaderIdNode, OutputRegisterIdNode, OutputRegisterHeaderIdNode, UIdNode, orderNode;

        public int iCount = 0;
        public int EId
        {
            set
            {
                _EId = value;
            }
            get
            {
                return _EId;
            }
        }
        public int CId
        {
            set
            {
                _CId = value;
            }
            get
            {
                return _CId;
            }
        }
        public AssignValues()
        {

        }
        public AssignValues(SqlCommand SqlComm,SqlConnection SqlConn)
        {
            Objdb = new Process();

            sqlcom=SqlComm;
            sqlcon = SqlConn;
        }

    public string check()
{
string x="hai";
return x
}
}
}

my Controller class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XYZ.ABC.Controllers;
using XYZ.ABC;

namespace XYZ.ABC.Controllers
{
    public class XYZ_Controller :Controller
    {

        public ActionResult XYZ_Checklist()
        {
            return View();
        }

    }
}

i want to call "public string check()" method in my controller class,is it possible? ,i am newbie in mvc, please help me to solve this.


You can simply call that in your MVC controller class

Follow the steps

1) Include the namespace of the class in MVC controller class

2) Inherit old class in Your MVC Controller

 Public Class MVCCOntrollerclassname: Class1

3) Create object of the .cs class

class1 c=new class1();

4) Create a constructor of MVC controller class

 MVCCOntrollerclassname()
        {
            c.methodname();

        }

Note : You say you are migrating asp.net to MVC , so if you have any asp.net dll then must change it as MVC Compitable dll


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK