Basics of Model-View-Controller (MVC4)

Description:Followings tips will be helpful for you at the time of making application using MVC4.0 where you have to take multiple controls. If you are beginner then you can easily use these tips as per requirements.

1) How to create listbox in view(.cshtml) in which user can select more than one values?

@Html.ListBoxFor(m=>m.property_of_model, ViewBag.name_of_viewbag as MultiSelectList, new {size = "8"})

2) How to call post method from view (.cshtml) ?

@using (Html.BeginForm("your action name", "your controller name", FormMethod.Post, new { id = "id you want to pass" }))

3) How to use grid in view (.cshtml) page?

var objgrid = new WebGrid(Model, rowsPerPage: 10);
@objgrid.GetHtml(htmlAttributes: new {id ="MyGrid"},
columns: objgrid.Columns(
objgrid.Column("", header: "", format: (col) => @Html.Raw(col.propoertyname))))

4) How to make action link for Edit?

@Html.ActionLink("Edit", "Edit", new { id = your_propertyname })

Through id field you can retrieve data and update. You have to write code in Edit actionlist to make it work.
5) How to make action link for delete?

@Html.ActionLink("Delete", "Delete", new { id = your_property_name })

You have to write code in Delete actionlink to make it work.
6) How to apply different css to controls at button click event using JQuery in MVC4.0?
btnSubmit is id of the button.

$('#btnSubmit').click(function () {
$.post('/your_namespace_name/controller_name/action_name', function (data) {
$('#controlid').css('display', 'none');
$('#controlid').css('display', 'block');


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: