web stats analysis

Asp.net mvc Archive

Disabling the right click on images in asp.net.

How to disable right click on images in asp.net?

Add below script between head tag


<script language="JavaScript" type="text/javascript">

var msg = "Right click disable.";
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
alert(msg);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(msg);
return false;
}
}
}
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
</script>
}

Add below code between body tag


<div>

Right click on page

</div>

How to use radio button list in asp.net mvc?

Radio button list in mvc

Radio button list in mvc razor.

Follow below Solution:-

@Html.RadioButtonFor(Model => Model.Gender, true) Male

@Html.RadioButtonFor(Model => Model.Gender, false) Female

How can I open a view in a new window with Html.ActionLink?

New window opens on click of actionLink

In Html.ActionLink() How to set target=_blank?

Clicking on actionlink will opening new window.

Follow below Solution:-

@Html.ActionLink("Click here", "About", "Home",null,  new { target = "_blank" })

How to replace spaces with underscores in asp.net?

How can I replace a space in a string with an underscore in C#?

Type following code in code behind.


protected void Page_Load(object sender, EventArgs e)

{

string text= "Good Morning";

Response.Write(Replace(text));

}

static string Replace(string t)

{

return System.Text.RegularExpressions..Regex.Replace(t, @"\s+", "_");

}

How to get Indian Rupee Symbol in C#.Net?

How to use paging in asp.net MVC 4?

Error: The name ‘CommandType’ does not exist in the current context.

Error: The name ‘SqlDbType’ does not exist in the current context.

Add following namespace

using System.Data;

How to change date format in c# asp .net?

Below asp.net date format example:


string format = "dd/MM/yyyy";

string date = Convert.ToDateTime("2013-09-05 09:34:43").ToString(format);

Response.Write(date.ToString());

How to get html controls value in controller?

How to pass value from view to controller?

How to pass textbox value to controller in asp.net mvc?

I have a solution is below:

You just Check below example:

I typed below code in my view



@using (Html.BeginForm("Add", "Student",FormMethod.Post))
{
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
Studemt Name : <input id="studname" id="studname" type="text" />
</td>

</tr>

<tr>
<td>
<input type="submit" name="submit" value="Submit" />
</td>
</tr>

</table>
}

I typed below code in my controller.



[HttpPost]
public ActionResult Add(FormCollection collection)
{
string name = collection.Get("studname");
return View();
}

The type or namespace name ‘RequiredAttribute’ could not be found (are you missing a using directive or an assembly reference?).

The type or namespace name ‘Required’ could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name ‘DisplayAttribute’ could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name ‘Display’ could not be found (are you missing a using directive or an assembly reference?)

I have a solution is below:

You just add below namespace:

using System.ComponentModel.DataAnnotations;