How to make false postback in asp.net mvc - postback

I have
Customer name : "Some Customer"
Country Dropdownlist
If ı choose country
Country's cities dropdownlist
ı can send country dropdownlist selected ıd then ı can show all cities in dropdownlist but customer name dissappears automaticly because of postback
how can ı make postback false in asp .net mvc ?

Related

Asp.net MVC DropDownList Add and Update

I am quite new to this as my background is ASP.net Web Form. I am faces with 3 issues as followed:
Dropdownlist postback and other dropdownlist is showen once the user selected the 1st dropdownlist.
2nd, I am trying to pass the dropdownlist selected value in adding data
#Html.DropDownList("CategoryID", ViewData["Category"] as List)
I am trying to update the data based on the selectedvalue
#Html.DropDownList("CategoryID", ViewData["Category"] as List)
I am able to populate it from the database.
Any advice would be helpful. Many thanks
The answer to this question is
#Html.DropDownListFor(model=> model.CategoryID, ViewData["Category"] as List<SelectListItem>)
and you use FormMethod.Post

how to add DropDownList to ASP.NET Identity?

I started to use ASP.NET Identity, and my question is how can I add a dropdownlist for gender (Male and Female) to my database?
I added a string value called "Gender" to my "AspNetUsers" table(with migrations in the cmd)
and I want to save there the values from the dropdownlist..
I'm using MVC but I can use Web Forms as well.
I saw this link: MVC4 Dropdown menu for Gender and I didn't understand how does it connect to the databse.
Thanks in advance.
In Controller
ViewBag.gender=new List<SelectListItem>(){
new SelectListItem(){Text="Male", Value="Male"},
new SelectListItem(){Text="Female", Value="Female"}
} ;
In view
#Html.DropDownListFor(
x => x.GenderId,
new SelectList(ViewBag.gender as List<SelectListItem>, "Value", "Text"))

how to store culture name in database

I try to develop a multilingual website, the problem that I have just to store the culture name in the database (for all the other data I'm using resource file)and I have to call it (culture name) from the view using dropdown list. Does anybody has an idea or examples?
For your point make Culture table with Id, culture code and Culture Name columns. Store culture code i.e. nl-NL and culture Name i.e. Dutch.
Then fetch them from db and create a list of it and bind them to dropdown. Bind culture code as value and culture name as Text of select dropdown. Use SelectListItem to do so like below:
this.ViewBag.Cultures = new SelectListItem(context.Cultures.Select(x=> new{ Id = x.CultureCode, Name = x.CultureName}), "Id", "Name").ToList();
Then on front end use dropdownlist:
#Html.DropdownList("Cultures", (IEnumerable<SelectListItem>)this.ViewBag.Cultures, "Select Culture")
Note: Store only those languages which you want to show on front side i.e. on UI.
You can ask me apart from this if you have any trouble.

kendo grid in inline editing mode with Dropdownlist required field

I have a kendo grid in inline editing mode. When I press "Add new item" button, new row is added. some editable fields are ForeignKey column in the grid, if i fill the text fields in the new records without filling or select the dropdownlist fields for ForeignKey columns, a null values are set for ForeignKey fields.
the question , how to enforce the user to select dropdownlist and make this field is required on "update" button click action.
i am using ASP.NET MVC 4.0 and Kendo UI for ASP.NET MVC Q2 2013.
Make sure your dropdownlists are binded to non nullable values, and are you using the EditorTemplate provided for the foreign key columns?

How to retrieve both Text and Value from DropDownList in Asp.net mvc

I have a dropdownlist in asp.net mvc which is bound using the normal binding syntax
and I can retrieve the "value" in the controller.
But I also need to display the text that is associated with this value.
I can go the hard route and query the db for this associated value.
But I wanted to know if there is an easy way to retrieve the Text as well as the Value in the controller.
Sample code I used
<%= Html.DropDownList("State","Pick a State")%>
which displays
"NJ", "New Jersey" etc.
In Controller
public ActionResult SelectState(string State)
{
// I have value of State (NJ) ...I also need the Text for this
}
Any help would be appreciated.
Thanks
The value that will come as part of the form submission is the value of the dropdown item. To get both, you could change the value to be something like "value delimiter text", so something like "NJ|New Jersey". Then you could parse it in the controller.

Resources