CountryController.
cs:-
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class CountryController : Controller
{
PAMS2017Entities2 obj = new PAMS2017Entities2();
[HttpGet]
public ActionResult Index()
{
return View([Link]());
}
private Country AutoGenerateId() //autogenerate
{
Country c = new Country();
var i = (from x in [Link]
orderby [Link] descending
select x).Take(1); //return max(id)
int y = 0;
foreach (var item in i)
{
y = [Link];
}
y++;
[Link] = "co_" + y;
return c;
}
[HttpGet]
public ActionResult Create()
{
Country c = AutoGenerateId();
return View(c);
}
[HttpPost]
public ActionResult Create(Country c1)
{
[Link](c1);
[Link]();
return View();
}
}
}
Code for [Link]:-
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class StateController : Controller
{
PAMS2017Entities2 obj = new PAMS2017Entities2();
public ActionResult Index()
{
return View([Link]());
}
private State AutoGenerateId() //autogenerate
{
State s = new State();
var i = (from x in [Link]
orderby [Link] descending
select x).Take(1); //return max(id)
int y = 0;
foreach (var item in i)
{
y = [Link];
}
y++;
[Link] = "st_" + y;
return s;
}
[HttpGet]
public ActionResult Create()
{
var country = [Link]();
State s = AutoGenerateId();
List<SelectListItem> li = new List<SelectListItem>();
[Link](new SelectListItem { Text = "Select country", Value = "0" });
foreach (var item in country)
{
[Link](new SelectListItem { Text = [Link], Value = [Link] });
}
TempData["c"] = li;
[Link]();
return View(s);
}
[HttpPost]
public ActionResult Create(State s1)
{
[Link](s1);
[Link]();
return View();
}
} }
Code for [Link]:-
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class CityController : Controller
{
PAMS2017Entities2 obj = new PAMS2017Entities2();
[HttpGet]
public ActionResult Index()
{
var city = [Link]();
return View(city);
public JsonResult getstate(string id)
{
var states = [Link](x => [Link] == id).ToList();
List<SelectListItem> listates = new List<SelectListItem>();
[Link](new SelectListItem { Text = "--Select State--", Value = "0" });
if (states != null)
{
foreach (var x in states)
{
[Link](new SelectListItem { Text = [Link], Value = [Link] });
}
}
return Json(new SelectList(listates, "Value", "Text", [Link]));
}
private City AutoGenerateId() //autogenerate
{
City s = new City();
var i = (from x in [Link]
orderby [Link] descending
select x).Take(1); //return max(id)
int y = 0;
foreach (var item in i)
{
y = [Link];
}
y++;
[Link] = "ct_" + y;
return s;
}
[HttpGet]
public ActionResult Create()
{
var country = [Link]();
City c = AutoGenerateId();
List<SelectListItem> li = new List<SelectListItem>();
[Link](new SelectListItem { Text = "Select country", Value = "0" });
foreach (var item in country)
{
[Link](new SelectListItem { Text = [Link], Value = [Link] });
}
TempData["s"] = li;
[Link]();
return View(c);
/* [HttpPost]
public ActionResult Create()
{
return View();
}*/
}
}
[Link](city):-
@model [Link]
@{
[Link] = "Create";
Layout = "~/Views/_AdminLayout.cshtml";
}
<h2>Create</h2>
@using ([Link]())
{
@[Link]()
<div class="form-horizontal">
<h4>City</h4>
<hr />
@[Link](true)
<div class="form-group">
@[Link](model => [Link], new { @class = "control-label
col-md-2" })
<div class="col-md-10">
@[Link](model => [Link])
@[Link](model => [Link])
</div>
</div>
<div class="form-group">
@[Link](model => [Link], new { @class = "control-
label col-md-2" })
<div class="col-md-10">
@[Link](model => [Link])
@[Link](model => [Link])
</div>
</div>
<div class="form-group">
@[Link](model => [Link], "Stateid", new { @class =
"control-label col-md-2" })
<div class="col-md-10">
@[Link]("State", new SelectList([Link], "Value",
"Text"), "--Select State--", new { style = "width:200px" })
@[Link](model => [Link])
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@[Link]("Back to List", "Index")
</div>
<script src="~/Scripts/[Link]"></script>
<script src="~/Scripts/[Link]"></script>
<script src="~/[Link]"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#country").change(function () {
$("#State").empty();
$.ajax({
type: 'POST',
url: '@[Link]("getstate")',
dataType: 'json',
data: { id: $("#country").val() },
success: function (states) {
$.each(states, function (i, state) {
$("#State").append('<option value="' + [Link] + '">' +
[Link] + '</option>');
});
},
error: function (ex) {
alert('Failed to retrieve states.' + ex);
}
});
return false;
})
});
</script>