Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Saturday, 23 May 2020

asp.net bind drop down list

@Html.DropDownListFor(x => x.itmunit, new List<SelectListItem>
    {
                        new SelectListItem() {Text = "Piece", Value="Piece"},
                        new SelectListItem() {Text = "Box", Value="Box"},
                        new SelectListItem() {Text = "Kg", Value="Kg"},
                        new SelectListItem() {Text = "Litre", Value="Litre"}
    }, new { @class = "form-control" })


Saturday, 11 April 2020

How to use Way2Sms api in C#

public void send(string message, string no)
{

HttpWebRequest myReq =
// (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password +
//"&msg=" + message + "&phone=" + no + "&provider=way2sms");
(HttpWebRequest)WebRequest.Create("puturlink = "+"UrUsername"+ "&password=" + "UrPassword" + "&sender=" +"UrSenderID"+ "&to=" +no+ "&message=" + message+ "&reqid=1&format={json|text}&route_id=route+id&callback=Any+Callback+URL&unique=1&sendondate=" +"10-10-2014T05:17:52"+"");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}

//Button Click code
protected void btn_send_Click(object sender, EventArgs e)
{

send(txt_message.Text, txt_mobile.Text);

ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('sms sent successfully...');", true);

}

Wednesday, 29 January 2020

How to get list through ajax jquery in c#

Here is simplify method with example please read and practice carefully then definitely you'll do this.

The first method is using get method..

$.ajax({
url:"/Home/GetUserList", /// this is URL  "HOME"- COntroller name, GetUserList-Method Name
type:"GET",   /// define type GET or POST
datatype:"json", /// datatype format
Content-Type:"application/json",
data:{}
success:function(response){
    alert("We got it user list").
}
error: function(response){
alert("we can't found the user list, there is something error");
}
})

Friday, 27 December 2019

How to Executing SQL Query in Entity Framework and Linq MVC C#

I will explain to you how we can use different types of SQL Query methods.

Introduction

 In this post, we will see how to execute native SQL queries, using DB Context.

 You can execute SQL queries using the following types of SQL Query methods. 

 1- SQL Query for a specific entity type.

 2- SQL Query for a primitive data type.

 3- SQL commands.


Let’s start.


SQL Query for a specific entity type


We can use SQLQuery() method to write SQL queries which return an entity object.


Example:


==============================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

var customerList = db.Customers.SqlQuery("Select * From Customers").ToList<Customers>();  

==============================================================

The code, shown above, selects all the data rows from customer's table. I would like to add that columns returned by SQLQuery must match the property of an entity type, otherwise it will throw an exception.


SQL Query for a primitive data type


In this type, the SQL Query() method will return any primitive types created using the SQL Query method.



Example:

========================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

int customerId = db.Database.SqlQuery<int>("Select customerId From Customers where customerName='MAHDI'").FirstOrDefault<int>(); 

========================================================

SQL commands


We can use ExcecuteSqlCommand() method to ensure the CRUD operation.


Example:

===========================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

int result = db.Database.ExecuteSqlCommand("delete from Customers where customerId = 100");  
===========================================================


As you can see, code displayed above will delete a customer that has 100 as customerId.

How to replacing escape characters from JSON in mvc c#


If the json object is a string, in .Net the escape "\" characters are added,
 should you want to clean up the json string, JObject.Parse({string}) as demonstrated
in the following code snippet cleans up nicely:

var myJsonAsString = "{\"Name\": \"John\", \"LastName\": \"Doe\", \"Age\": 199 }";

var myCleanJsonObject = JObject.Parse(myJsonAsString);
Should give us a clean Json object with the escape characters removed.
{
"Name": "John",
"LastName": "Doe",
"Age": 199
}

Thursday, 5 December 2019

Display Current Time in C# (C Sharp)


var ab= DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);
var cd=  DateTime.Now.ToString("hh:mm:ss.fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);

redirect to new page from jquery

  function foo(id) { var url = ' @Url . Action ( "Details" , "Branch" , new { id = "__id__" })'...