|
I am trying to incorporate a ViewModel as I am using edmx file to define my db, but my view only works with the edmx model and sends an unexpected result when I use my ViewModel.
My ViewModel is;
public class GetQuestionViewModel
{
public class Question {
public Question Questions { get; set; }
public Response Response { get; set; }
}
public GetQuestionViewModel()
{
this.QuestionOptions = new HashSet<QuestionOption>();
this.Responses = new HashSet<Response>();
}
[Key]
public int Id { get; set; }
public int PageNumber { get; set; }
public string Question1 { get; set; }
public int QuestionTypeId { get; set; }
public Nullable<int> LinkedTo { get; set; }
public Nullable<int> Options { get; set; }
public Nullable<int> QuestionRanking { get; set; }
public virtual ICollection<QuestionOption> QuestionOptions { get; set; }
public virtual QuestionType QuestionType { get; set; }
public virtual ICollection<Response> Responses { get; set; }
}
And my Action is;
[HttpGet]
public ActionResult ViewQuestion(int? id)
{
if (id == null || id == 0 || id > 13)
{
id = 8;
}
Question question = db.Questions.Find(id);
if (question == null)
{
return HttpNotFound();
}
return View(question);
}
I tried changing the
Question question = db.Questions.Find(id); to
var question = db.Questions.Find(id);
but nothing I have tried works. I want to get the ViewModel working before I build the query;
Question questions = (from q in db.Questions
from qo in q.QuestionOptions.DefaultIfEmpty()
from r in q.Responses.DefaultIfEmpty()
where q.PageNumber == page && r.UserId == userId
select new Question
{
Id = q.Id,
QuestionType = q.QuestionType,
Question1 = q.Question1
}
This is my first MVC project and I am really struggling although I have followed several online tutorials. I would be grateful for any help.
|
|
|
|
|
|
im using datalist control to display the data long with image, address and button.im using label control to display the data in datalist. if i click on more button in datalist control the page must be redirected to that particular page. But i could not do this.how to redirect when i click on button in datalist to that page ?
|
|
|
|
|
which technology give more scope in future in prospect of learning
|
|
|
|
|
All of them. You are asking us to foretell the future, and even the industry experts don't always get it right.
Veni, vidi, abiit domum
|
|
|
|
|
As a part of project I need to present a 3D scatter plot in a web page based on the 3 columns data from a table from database. Is there a way to draw a 3d scatter plot in ASP.Net.
|
|
|
|
|
|
Good day everybody. I'm designing a chat with asp.net, and everything is working except one.
I want to retrieve the newest 15 records then delete the old ones. I used count to get the number of records in my table then specify that if count is equal to 20, then, I used sql Top statement to delete the Top 5 messages. But I found that sql server sort whatever is inserted in alphabetical order. And this technique delete both the newest messages. Please, some should tell me how to achieve this. Thanks in advance.
|
|
|
|
|
You need to sort the messages into the correct order first. Use the SQL ORDER BY clause[^].
Veni, vidi, abiit domum
|
|
|
|
|
Goodmorning to everyone!
I've putted this xml file into mediafire hosting. Here its link:
LINK MEDIAFIRE FILE.XML
And there is my stupid code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace ProvaParsingXml
{
class Program
{
static void Main(string[] args)
{
string str = @"C:\Users\c.capannini\Desktop\file.xml";
XDocument xml = XDocument.Load(str);
var hosts = from h in xml.Descendants("address")
select new
{
addr = h.Attribute("addr").Value,
addrtype = h.Attribute("addrtype").Value,
};
foreach (var host in hosts)
{
if (host.addrtype == "ipv4" || host.addrtype == "ipv6")
{
Console.WriteLine("Host : " + host.addr.ToString());
var ports = xml.Descendants("port");
foreach (var port in ports)
{
Console.WriteLine("Port = " + port.Attribute("portid").Value.ToString());
var script = port.Element("script");
if (script != null)
{
var pem = script.Descendants("elem").FirstOrDefault(n => n.Attribute("key").Value == "pem");
string pemm = pem.ToString();
pemm = pemm.Replace("<elem key=\"pem\">", "");
pemm = pemm.Replace("</elem>", "");
Console.WriteLine("PEM = " + pemm);
break;
}
}
}
}
Console.ReadLine();
}
}
}
Why don't the port and pemm string not change? How can i get for each host their ports and for each port the string value inside tag <elem key="pem"> ?
How can i do it?
Please help me. I'm going crazy!!!
Thanks!
|
|
|
|
|
An XML comment in the file says that it was generated ny nmap. Hence I'd suggest to look at the nmpa documentation for an XML Schema Definition file (xsd). You can create corresponding classes from the xsd automatically.
|
|
|
|
|
Hello friends, please I need your advice on this. I'm designing a site where students can pay their school fees online. I have a page where students can enter their bank details then submit for confirmation. Now, the challenge is how can I verify if the bank details are existing, then, if the details exist, the school fee amount should be deducted from his/her acount then transfer the money to the schools' account? Please give any ideal. Thanks for your help so far because without your help, I wouldn't have reached this stage in programming. I'm using asp.net
|
|
|
|
|
This is called a payment gateway or payment processing. You need to sign up with one and integrate its API to process payments. Search Google for "asp.net payment gateway".
Edit:
Also, unless you want to be financially responsible for any breach of data that happens with your students bank details, I would avoid storing these details on your own system, use a gateway that allows storage of these on their site like PayPal so you aren't held responsible for it. Even big companies make mistakes (look up Target data breach), so avoid it at all costs.
|
|
|
|
|
Thanks Ron. I will use the method suggested by you.
|
|
|
|
|
But, when I have signed up with this paypal stuff, how will the processing take place? Do I have to provide the school's account to the paypal site?
|
|
|
|
|
Paypal has a help page that gives all that information, but in short, yes, you have to associate a real bank account with the paypal account in order for you to transfer funds.
|
|
|
|
|
It's called ACH
You use a payment gateway like authorize.net, pay the extra $20 a month, then code to the API and submit like a credit card.
I think you have to have a merchant account first, then select your compatible payment gateway, and then code to that API.
PayPal does it, but I think it's $6.00 per hundred to convert the paypal currency to US Dollars
|
|
|
|
|
Thanks Jkirkerx. After registering with this paypal company, do still need code in my website? If yes, how? Because I have no knowlege about this. You can direct me to some link that can help me know more details on how to achieve the coding of the API.
How does the payment looks like? Is it every year I will pay this comapny or every month?
Once again, thanks for reply!
|
|
|
|
|
|
|
Why have you reposted this here? This is not an ASP.NET issue, please use the correct forum. And I notice that you already posted this in Q&A and have been asked to provide details of the error.
Veni, vidi, abiit domum
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
using System.Drawing;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
openFileDialog1.Title = "Insert Image";
openFileDialog1.ShowDialog();
openFileDialog1.Filter = "JPEG Images|*.jpg|GIF Images|*.gif";
//object r = new object();
EventArgs en = new EventArgs();
string s1 = richTextBox1.Text;
string s2 = richTextBox2.Text;
string s3 = richTextBox3.Text;
string Chosen_File = "";
Chosen_File = openFileDialog1.FileName;
pictureBox1.Image = Image.FromFile(Chosen_File);
byte[] byteData = imageToByteArray(pictureBox1.Image);
string ToS1 = byteData.ToString();
Byte[] newdata = encoding.GetBytes(ToS1);
Byte[] encrypted = myrsa.Encrypt(newdata, false);
for (int i = 0; i < encrypted.Length; i++)
richTextBox4.Text += encrypted[i].ToString();
Byte[] decrypted = myrsa.Decrypt(encrypted, false);//decrypt
pictureBox2.Image = byteArrayToImage(decrypted);
}
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
}
Problem in Code :: When we decrypt the image back then it shows an error in "Image.FromStream(ms): during run time.
|
|
|
|
|
1. This has nothing to do with ASP.NET; please use the correct forum.
2. Please put your code between <pre> tags; use the code button above the edit window.
3. Please provide details of the error; where does it occur, and what is the exact text of the message?
Veni, vidi, abiit domum
|
|
|
|
|
Hello,
After converting MVC 4 project to MVC 5 I am getting an error "this website has redirect loop". In my web.config file I have the following:
<authentication mode="Forms">
<forms loginurl="Account/Register" timeout"2880:="">
When I try to click on any menu item, it tries to redirect to /Account/Register page. This was working fine before the conversion. How do I resolve this?
Thanks.
|
|
|
|
|
this code doesnt work in page which has masterpage ?
<asp:content id="Content1" contentplaceholderid="ContentMaster" runat="Server">
<script type="text/javascript">
$(document).ready(function() {
$('html,body').animate({ scrollTop: 150 }, 1000);
});</script>
|
|
|
|