|
In order to get your code working as it is you need a CategoryList property on your model
public class MerchandiseViewModel
{
public int CategoryList { get; set; }
}
To use DropDownListFor;
public class MerchandiseViewModel
{
public Category Category { get; set; }
}
public ActionResult Test()
{
List<Category> cats = new List<Category>();
cats.Add(new Category { ID = 1, Name = "Category 1" });
cats.Add(new Category { ID = 2, Name = "Category 2" });
cats.Add(new Category { ID = 3, Name = "Category 3" });
ViewBag.CategoryList = cats;
return View();
}
[HttpPost]
public ActionResult Test(MerchandiseViewModel mvm)
{
List<Category> cats = new List<Category>();
cats.Add(new Category { ID = 1, Name = "Category 1" });
cats.Add(new Category { ID = 2, Name = "Category 2" });
cats.Add(new Category { ID = 3, Name = "Category 3" });
ViewBag.CategoryList = cats;
return View(mvm);
}
view;
@using (Html.BeginForm())
{
<p>
@Html.DropDownListFor(m => m.Category.ID, new SelectList(ViewBag.CategoryList, "ID", "Name"), "Select a category")
</p>
<p>
<input type="submit" value="Submit"/>
</p>
}
Note I put the categories in the ViewBag and do the convert to SelectList in the view, that just means that if you want to use the categoires elsewhere on the view you still can.
|
|
|
|
|
Thank you so much for replying. I see what you are trying to do, unfortunately its not working for me since my situation is a little different than what you've posted above.
Below is a snippet of the MerchandiseServiceClient class definition inside of the Models folder
public class MerchandiseServiceClient
{
private string BaseURL = "http://localhost:14000/MerchandiseService.svc/";
public Merchandise FindMerchandiseByID(string id)
{
try
{
var webClient = new WebClient();
string url = string.Format(BaseURL + "FindMerchandiseByID/{0}", id);
var javascriptSerializer = new JavaScriptSerializer();
return javascriptserializer.Deserialize<Merchandise>(jsn);
}
catch
{
return null;
}
}
public List<Category> FindAllCategories()
{
try
{
var webClient = new WebClient();
var jsn = webClient.DownloadString(BaseURL + "FindAllCategories");
var javascriptSerializer = new JavaScriptSerializer();
return javascriptSerializer.Deserialize<List<Category>>(jsn);
}
catch
{
return null;
}
}
.
.
.
.
}
The MerchandiseServiceClient class is one of many classes in the Models folder. The FindAllCategories() method of the MerchandiseServiceClient class gets JSON data from a RESTful WCF service and it returns a List of Category objects.
I tried to use this List of Category objects to populate the dropdownlist but it is not working. Please see my code below.
MerchandiseController
[HttpGet]
public ActionResult Edit(string id)
{
MerchandiseServiceClient msc = new MerchandiseServiceClient();
ViewBag.categoryList = msc.FindAllCategories();
MerchandiseViewModel mvm = new MerchandiseViewModel();
mvm.Merchandise = msc.FindMerchandiseByID(id);
return View("Edit", mvm);
}
Edit View
<tr>
<td>@Html.LabelFor(model=>model.Category.ID, "Category")</td>
<td> @Html.DropDownListFor(model => model.Category.ID, (SelectList)ViewBag.categoryList, "Select A Category")</td>
</tr>
modified 21-Jul-16 11:35am.
|
|
|
|
|
@Html.DropDownListFor(model => model.Category.ID, (SelectList)ViewBag.categoryList, "Select A Category")</
In the above ViewBag.categoryList can't be cast to SelectList as it isn't of that type and can't be converted to that type. You need something similar to my posted code
@Html.DropDownListFor(m => m.Category.ID, new SelectList(ViewBag.categoryList, "ID", "Name"), "Select a category")
Replace "ID" and "Name" with the properties on the Category class that you want to be used for the value and the text.
|
|
|
|
|
Well I'm late to the party here, but since I'm trying to fix my VS2015 SP3 problem here, and waiting for the VS2015 with SP3 to load, I'll throw in my 2 cents.
I found it best to create a
Dictionary<string, string> Categories { get; set; }
So if you have a model
public class model_items
{
int ID { get; set; }
string SKU { get; set; }
int CategoryID { get; set; }
Dictionary<string, string> select_Categories { get; set; }
}
This like FSSiteCore said, you use his example in the View
@Html.DropDownFor(m => m.CategoryID, new SelectList(@Model.selectCategory), "-- Select Category --")
To populate the model in the controller
model_items model = new model_items();
model = load_items(1);
model.selectCategories = load_Categories();
Then you write a function that loads a Dictionary of string string. You can write a function using EF to load the Category Key and value, and then package those as a Dictionary.
I have found this to be the best way to do it for me so far, being on my 3rd MVC project now.
Reason being is well the SelectList in Razor likes Dictionaries and takes them well with no problems.
|
|
|
|
|
Message Closed
modified 19-Jul-16 8:13am.
|
|
|
|
|
Try changing your DropDownList call to:
@Html.DropDownListFor(model => model.Category.ID, ViewBag.CategoryList, "Select Category")
The version you're using at the moment renders a list with the name "CategoryList" , which doesn't seem match any of the properties on your view-model.
Also, it's not clear how the Category property on your view model is implemented. I'm assuming it delegates to a property on the Merchandise ? If not, you'll need to connect the two objects in the POST method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
how to insert a img in database
|
|
|
|
|
By writing lots of code. Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
When your image uploads, it's usually uploaded as a base64 string that represents bytes.
You can just save the Base64 string in the database column, or convert the string to a byte.array, and save the image as bytes in the database. With bytes, you can write the byte array to the disk drive as an image. So get use to converting the data. Another cool thing about storing as bytes is that you can pump those bytes into a function to resize the images, tweak it and send it back out as bytes.
Remember in your database design, to include the filename, the url of where you would want to store the image for the browser to fetch, and the type, jpeg, png.
I have post from 3 months ago that talks about this.
|
|
|
|
|
How can i create a setup for asp.net application in visual studio 2015?
|
|
|
|
|
There are different ways to create deployment package
You can create a package in the following ways:
- Use tools in Visual Studio.
- Use the MSBuild command directly from the command line.
- Use the MSBuild command indirectly from PowerShell or Team Build.
- One-Click Publish (Click once deployment)
see below link for more details
ASP.NET Web Application Project Deployment Overview[^]
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
It depends where you want to deploy. We are using publish into AWS cloud.
|
|
|
|
|
Dear members,
I worked on ASP.NET 2.0 and C# last in 2011, and after that worked on some other field. Now I have to use ASP.NET back for a website development. But i guess a lot has changed over the years.
I just need to know whether I have to get started all over again, or are there some things that I should now understand first.
Thanks
|
|
|
|
|
That is impossible to answer in a forum like this. Things change so rapidly now that 5 years worth of changes means you have a lot to catch up on. The best place to start would be the ASP.NET website[^].
|
|
|
|
|
MVC is a big addition from 2011. You can still do WebForms (I am) but I think many would argue that MVC is the current way to go. Many use angular.js with MVC.
There is also the Entity Framework which you may have not used. I don't care for it but that may be because I don't use it properly.
Lambda and LINQ are probably new to you but are not ASP.Net specific but can be very useful.
If you didn't use jQuery that has become very big.
Good luck. Lots of good articles on this site.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
2.0 was long back then after 3.0, 3.5, 4.0, 4.5, 4.5.2 was introduced each has their different features, here are listed below
for 3.0/3.5
- Windows Presentation Foundation (WPF)
- Windows Communication Foundation (WCF)
- Windows Workflow Foundation (WWF)
- Windows Card Space (WCS)
for 4.0
- Application Compatibility and Deployment
- Managed Extensibility Framework
- Parallel Computing
- Networking
- Web
- Client
- Data
- Windows Communication Foundation
.Net Framework 4.5 Features
- .NET for Windows Store Apps
- Portable Class Libraries
- Core New Features and Improvements
- Tools
- Parallel Computing
- Web
- Windows Presentation Foundation (WPF)
- Windows Communication Foundation (WCF)
- Windows Workflow Foundation (WF)
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
Why can't check yourself in official ASP.NET website?
|
|
|
|
|
What the others said.
However, you should consider your own situation. WebForms still works fine. MVC is "cooler" but the transition from WebForms to MVC.NET is not easy.
If you used the AJAX Toolbox (or whatever it was called): it's been abandoned. Instead, MS chose to support the community behind jQuery.
So if you're just updating an existing site, perhaps you would get by simply making things nicer with jQuery. If on the other hand you would like to be more up to date, you should probably look into MVC.NET (and perhas some of the other things mentioned in these replies).
The problem with web development is that things move so fast that as soon as you get the hang of a language or framework, it's almost obsolete, especially if you're not working with web development on a daily basis.
|
|
|
|
|
In a vb.net 2010 web form application, I have a request from the user to be able to insert,update, and/or delete a row
in a single table. Thus I have the following questions to ask:
1. I am trying to decide if I should use a detailsviews, formview, gridview, and/or a different control for this purpose.
Thus would you tell me what control you would recommend and why you would recommend that particular control?
2. For the different options for insert, update, and delete, would I use the buttons that are on the control that you
recommend? If not would I use, new buttons that I place on the webform page?
3. For the control that you recommend that I use, should I place the sql 'embedded' in the sqldatasource, the control
you recommend and/or access the sql from a different location(vb.net code in a new location)?
Would you tell me , show me with pictures, and/or point to me to links (urls) that will show me how to accomplish
this
|
|
|
|
|
The traditional way of solving this is using a master/detail scenario:
1. Drag a gridview to the site, and bind it to the database's table. Rightclick it and choose to have a Select field shown.
2. Drag a details view to the page, and bind it as well. In its bidning window, you can graphically set a WHERE statement. Set your statement to Control, then chose your gridview as the control. Also click the advanced button to enable DELETE, UPDATE, and INSERT.
If done right, this means that when a user clicks the Select button for a particular row in the gridview, this row's data will appear in the detailsview. Then it can be updated or deleted, and more data can be inserted from the detailsview.
I don't know how much you know about binding to a database, but be sure you stay out of SQL injection trouble.
Note that searching for master/detail, gridview and detailsview you should be able to fond a lot of info on how to do this.
Good luck!
|
|
|
|
|
Hi,
I am new to ADFS SSO implementation via SAML 2.0.Could you please guide any one to accomplish below requirement.
I have requirement to implement single sign on using ADFS,once you click on sign in through adfs button it should create saml request like mydomainname/adfs/ls/?SAMLRequest="" then it will redirect to ADFS login page then after successfully validation adfs should send response to our consumer page which our back end code will validate the response if it is valid then proceed further.
It is urgent requirement.quick response will help my day simpler.It will great if some one shared related link to follow.
Thanks for your help in advanced.
Regards,
Prasanna
|
|
|
|
|
|
Hello. I have a side panel that is layed out like this:
<div class="panel panel-default">
<div class="panel-heading">
<h4>To Do</h4>
</div>
<ul class="list-group">
<asp:Repeater runat="server" ID="rptToDo">
<ItemTemplate>
<li class="list-group-item"><a href="Landing.aspx?Don=<%# Eval("ID") %>">X</a> <a href="Details.aspx?ID=<%# Eval("ID") %>"><%# Eval("ItemName") %></a></li>
</ItemTemplate>
</asp:Repeater>
<li class="list-group-item">
<asp:Panel runat="server" DefaultButton="btnAddToDo">
<input type="text" runat="server" id="txtAddToDo" class="form-control" placeholder="Add Item" />
<asp:Button runat="server" ID="btnAddToDo" Style="visibility: hidden;" OnClick="btnAddToDo_Click"></asp:Button>
</asp:Panel>
</li>
</ul>
</div>
Instead of having that text box at the bottom to add new records to, I'd like to put a good button or link of some sort to the right of my title , but still inside the gray area. I can't quite seem to get it to line up. Any help would be greatly appreciated.
|
|
|
|
|
It's looks like your using bootstrap with webforms. I haven't seen anybody do that yet. Interesting.
You would have to divide the title using the row and grid that bootstrap provides, because grids can only be childs of row.
<div class="panel-heading">
<div class="row">
<div class="col-sm-8">
<h4>To Do</h4>
</div>
<div class="col-sm-4">
<button class="btn btn-primary" type="button">Add +</button>
</div>
</div>
</div>
|
|
|
|
|
Hi All,
As per our client request, I am going to convert our MVC 4 application into ASP.Net core. What are all the common development and deployment difficulties that may occur during conversion process? Please provide your valuable suggestions on this.
Best Regards,
Simiyon A
modified 12-Jul-16 5:09am.
|
|
|
|
|